d2-utilizr
Advanced tools
Comparing version 0.2.15 to 0.2.16
@@ -7,2 +7,5 @@ 'use strict'; | ||
exports.default = arrayRepeat; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
/** | ||
@@ -29,2 +32,3 @@ * | ||
if (typeof array === 'undefined') { | ||
@@ -34,11 +38,21 @@ throw 'Cannot repeat array of type undefined'; | ||
var newArray = []; | ||
if (byIndex) { | ||
return [].concat.apply([], array.map(function (item, i) { | ||
return Array(n).fill(array[i]); | ||
})); | ||
for (var i = 0; i < array.length; i++) { | ||
for (var j = 0; j < n; j++) { | ||
newArray.push(array[i]); | ||
} | ||
} | ||
return newArray; | ||
} | ||
return [].concat.apply([], Array.apply(null, Array(n)).map(function () { | ||
return array; | ||
})); | ||
for (var _i = 0; _i < n; _i++) { | ||
newArray.push.apply(newArray, _toConsumableArray(array)); | ||
} | ||
return newArray; | ||
}; | ||
//# sourceMappingURL=arrayRepeat.js.map |
{ | ||
"name": "d2-utilizr", | ||
"version": "0.2.15", | ||
"version": "0.2.16", | ||
"description": "d2-utilizr", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -19,2 +19,3 @@ /** | ||
export default function arrayRepeat(array, n=1, byIndex=false) { | ||
if (typeof array === 'undefined') { | ||
@@ -24,7 +25,21 @@ throw `Cannot repeat array of type undefined`; | ||
let newArray = []; | ||
if (byIndex) { | ||
return [].concat.apply([], array.map((item, i) => Array(n).fill(array[i]))); | ||
for (let i=0; i<array.length; i++) { | ||
for (let j = 0; j < n; j++) { | ||
newArray.push(array[i]); | ||
} | ||
} | ||
return newArray | ||
} | ||
return [].concat.apply([], Array.apply(null, Array(n)).map(() => array)); | ||
for (let i=0; i<n; i++) { | ||
newArray.push(...array); | ||
} | ||
return newArray | ||
}; | ||
Sorry, the diff of this file is not supported yet
278195
2162
122