UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

41 lines (40 loc) 1.15 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.times = void 0; const baseTimes_1 = __importDefault(require("./.internal/baseTimes")); const getIteratee_1 = __importDefault(require("./.internal/getIteratee")); const toInteger_1 = __importDefault(require("./toInteger")); /** * @ignore * @private * @internal */ const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; /** * @ignore */ const MAX_ARRAY_LENGTH = 4294967295; /** * @ignore */ const nativeMin = Math.min; function times(n, iteratee) { n = (0, toInteger_1.default)(n); if (n < 1 || n > MAX_SAFE_INTEGER) { return []; } let index = MAX_ARRAY_LENGTH; const length = nativeMin(n, MAX_ARRAY_LENGTH); iteratee = (0, getIteratee_1.default)(iteratee); n -= MAX_ARRAY_LENGTH; const result = (0, baseTimes_1.default)(length, iteratee); while (++index < n) { iteratee(index); } return result; } exports.times = times; exports.default = times;