was.js
/trunk/lib/collections/arrays/arrays.js |
@@ -41,16 +41,9 @@ |
}); |
} |
|
/*************************************************************************/ |
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
/*************************************************************************/ |
// Vanilla JavaScript |
function wasChunk(a, n) { |
if (!a.length) { |
return []; |
} |
return [a.slice(0, n)] |
.concat(a.slice(n).wasChunk(n)); |
return new Array.from(new Array(Math.ceil(a.length/n)), (_,i)=>a.slice(i*n,i*n+n)); |
} |
if (!Array.prototype.chunk) { |
Array.prototype.chunk = function(a, n) { |