Last active
February 25, 2023 18:24
-
-
Save rodpoblete/2ff70a36781ba69b7d3e6c02f624fe22 to your computer and use it in GitHub Desktop.
Dividir array en grupo de arrays - FCC [251]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// array.prototype.push() | |
// array.prototype.slice(); | |
function chunckArrayInGroups(arr, size) { | |
var chunk = [], i; // declara array vacio e indice de for | |
for (i = 0; i <= arr.length; i+= size) // loop que recorre el array | |
chunk.push(arr.slice(i, i + size)); // push al array el tramo desde el indice del loop hasta el valor size + el indicador | |
return chunk; | |
} | |
chunckArrayInGroups(["a", "b", "c", "d"], 2); | |
// [["a", "b"], ["c","d"]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment