Skip to content

Instantly share code, notes, and snippets.

@Daniel-Hug
Created July 14, 2015 05:30
Show Gist options
  • Save Daniel-Hug/4ebff6fffdb0eb4ae8e6 to your computer and use it in GitHub Desktop.
Save Daniel-Hug/4ebff6fffdb0eb4ae8e6 to your computer and use it in GitHub Desktop.
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