Last active
July 5, 2023 11:48
-
-
Save alexalannunes/081f3d807cfd42fbb5f0233af88f4656 to your computer and use it in GitHub Desktop.
divide array
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
const a = [1,2,3,4,5,6,7,8] | |
const newarr=[] | |
const cols = 4 | |
const interactions = a.length/cols | |
let index = 0 | |
console.log(interactions) | |
for (let i = 0; i < interactions;i++) { | |
const slice = a.slice(index, index + cols) | |
newarr.push(slice) | |
index += cols | |
} | |
newarr // [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment