UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

58 lines (57 loc) 2.02 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.some = void 0; // @ts-nocheck const isArray_1 = __importDefault(require("./isArray")); const isIterateeCall_1 = __importDefault(require("./.internal/isIterateeCall")); const getIteratee_1 = __importDefault(require("./.internal/getIteratee")); const baseEach_1 = __importDefault(require("./.internal/baseEach")); /** * A specialized version of `some` for arrays without support for iteratee * shorthands. * * @private * @param array The array to iterate over. * @param predicate The function invoked per iteration. * @returns Returns `true` if any element passes the predicate check, * else `false`. */ function arraySome(array, predicate) { let index = -1; const length = array == null ? 0 : array.length; while (++index < length) { if (predicate(array[index], index, array)) { return true; } } return false; } /** * The base implementation of `some` without support for iteratee shorthands. * * @private * @param {Array|Object} collection The collection to iterate over. * @param {Function} predicate The function invoked per iteration. * @returns {boolean} Returns `true` if any element passes the predicate check, * else `false`. */ function baseSome(collection, predicate) { let result; (0, baseEach_1.default)(collection, (value, index, collection) => { result = predicate(value, index, collection); return !result; }); return !!result; } function some(collection, predicate, guard) { const func = (0, isArray_1.default)(collection) ? arraySome : baseSome; if (guard && (0, isIterateeCall_1.default)(collection, predicate, guard)) { predicate = undefined; } return func(collection, (0, getIteratee_1.default)(predicate, 3)); } exports.some = some; exports.default = some;