-
-
Save Aldhanekaa/85526e68ae977071b18d4d1c6348ffd5 to your computer and use it in GitHub Desktop.
my FreeCodeCamp Basic Algorithm Scripting, Chunky Monkey
This file contains 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
function chunkArrayInGroups(arr, size) { | |
var newArray = []; | |
for (let i = 0; i<arr.length; i++) { | |
// console.log(i) | |
if (i == 0) { | |
newArray.push(arr.slice(i, size )) | |
}else if (i % size == 0 && i != 0) { | |
// console.log('HEY!') | |
// console.log(arr[i]) | |
// console.log(arr.indexOf(arr[i])) | |
let x = arr.indexOf(arr[i]) | |
console.log(x) | |
x = arr.slice(x, x + size) | |
newArray.push(x) | |
} | |
} | |
return newArray; | |
} | |
console.log(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment