/
lostSun
/
project-client-server-apps
Обзор
Документация
Войти
/
lostSun
/
project-client-server-apps
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
node_modules/underscore/amd/_linearSearch.js
31 строка
1 KB
1lostsun
initial commit
05 май 2025, 11:35
05 май 2025, 11:35
fe8f535
Код
Авторство
О чём код?
define(['./_getLength', './isFunction'], function (_getLength, isFunction) { // Internal function for linearly iterating over arrays. function linearSearch(array, predicate, dir, start) { var target, length = _getLength(array); dir || (dir = 1); start = ( start == null ? (dir > 0 ? 0 : length - 1) : start < 0 ? (dir > 0 ? Math.max(0, start + length) : start + length) : dir > 0 ? start : Math.min(start, length - 1) ); // As a special case, in order to elide the `predicate` invocation on every // loop iteration, we allow the caller to pass a value that should be found by // strict equality comparison. This is somewhat like a rudimentary iteratee // shorthand. It is used in `_.indexof` and `_.lastIndexOf`. if (!isFunction(predicate)) { target = predicate && predicate.value; predicate = false; } for (; start >= 0 && start < length; start += dir) { if ( predicate ? predicate(array[start], start, array) : array[start] === target ) return start; } return -1; } return linearSearch; });