Created
April 3, 2018 18:18
-
-
Save irrationnelle/6770c73250a6f64e29399d89e2b5a73b to your computer and use it in GitHub Desktop.
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 array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; | |
const twoDimensionArray2 = array.reduce((array, number, index) => { | |
const criteria = 4; | |
const arrayIndex = Math.floor(index / criteria); | |
if (!array[arrayIndex]) { | |
array[arrayIndex] = []; | |
} | |
array[arrayIndex] = [...array[arrayIndex], number]; | |
return array; | |
}, []); | |
console.log(array); | |
console.log(twoDimensionArray2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment