@re-flex/ui
Version:
Re-Flex ui library
21 lines (20 loc) • 519 B
JavaScript
const MAX_SAFE_INTEGER = 9007199254740991;
const MAX_ARRAY_LENGTH = 4294967295;
function times(n, iteratee) {
if (n < 1 || n > MAX_SAFE_INTEGER) {
return [];
}
let index = -1;
const length = Math.min(n, MAX_ARRAY_LENGTH);
const result = new Array(length);
while (++index < length) {
result[index] = iteratee(index);
}
index = MAX_ARRAY_LENGTH;
n -= MAX_ARRAY_LENGTH;
while (++index < n) {
iteratee(index);
}
return result;
}
export default times;