Bones/node_modules/filled-array/index.js

16 lines
288 B
JavaScript
Raw Normal View History

2017-05-17 13:45:25 -04:00
'use strict';
module.exports = function (item, n) {
var ret = new Array(n);
var isFn = typeof item === 'function';
if (!isFn && typeof ret.fill === 'function') {
return ret.fill(item);
}
for (var i = 0; i < n; i++) {
ret[i] = isFn ? item(i, n, ret) : item;
}
return ret;
};