Last active
February 19, 2019 22:09
-
-
Save cutty853/5892b07b2f934911124c32f34bac5746 to your computer and use it in GitHub Desktop.
Algorithm to tile an array. Written in NodeJS
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
/** | |
* Produce a list of list by tiling the originalArray. | |
* | |
* @param {int} tileAmount amount of tiles per ligne | |
* @param {Array} originalArray the array to tile | |
*/ | |
function tiler(tileAmount, originalArray) { | |
tiles = []; | |
for (let index = 0; index < originalArray.length; index++) { | |
const element = originalArray[index]; | |
if (index % tileAmount == 0) { | |
tiles.push([]); | |
} | |
tiles[Math.floor(index / tileAmount)].push(element); | |
} | |
return tiles; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment