Created
July 14, 2015 05:30
-
-
Save Daniel-Hug/4ebff6fffdb0eb4ae8e6 to your computer and use it in GitHub Desktop.
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
function arrayTo2d(items, width) { | |
var rows = []; | |
var lastRow; | |
items.forEach(function(item, i) { | |
// add another row when cell index is divisble by width | |
if ((i) % width === 0) { | |
lastRow = []; | |
rows.push(lastRow); | |
} | |
lastRow.push(item); | |
}); | |
return rows; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment