You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					29 lines
				
				977 B
			
		
		
			
		
	
	
					29 lines
				
				977 B
			| 
								 
											3 years ago
										 
									 | 
							
								import getLength from './_getLength.js';
							 | 
						||
| 
								 | 
							
								import { slice } from './_setup.js';
							 | 
						||
| 
								 | 
							
								import isNaN from './isNaN.js';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								// Internal function to generate the `_.indexOf` and `_.lastIndexOf` functions.
							 | 
						||
| 
								 | 
							
								export default function createIndexFinder(dir, predicateFind, sortedIndex) {
							 | 
						||
| 
								 | 
							
								  return function(array, item, idx) {
							 | 
						||
| 
								 | 
							
								    var i = 0, length = getLength(array);
							 | 
						||
| 
								 | 
							
								    if (typeof idx == 'number') {
							 | 
						||
| 
								 | 
							
								      if (dir > 0) {
							 | 
						||
| 
								 | 
							
								        i = idx >= 0 ? idx : Math.max(idx + length, i);
							 | 
						||
| 
								 | 
							
								      } else {
							 | 
						||
| 
								 | 
							
								        length = idx >= 0 ? Math.min(idx + 1, length) : idx + length + 1;
							 | 
						||
| 
								 | 
							
								      }
							 | 
						||
| 
								 | 
							
								    } else if (sortedIndex && idx && length) {
							 | 
						||
| 
								 | 
							
								      idx = sortedIndex(array, item);
							 | 
						||
| 
								 | 
							
								      return array[idx] === item ? idx : -1;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    if (item !== item) {
							 | 
						||
| 
								 | 
							
								      idx = predicateFind(slice.call(array, i, length), isNaN);
							 | 
						||
| 
								 | 
							
								      return idx >= 0 ? idx + i : -1;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    for (idx = dir > 0 ? i : length - 1; idx >= 0 && idx < length; idx += dir) {
							 | 
						||
| 
								 | 
							
								      if (array[idx] === item) return idx;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    return -1;
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								}
							 |