Skip to content

Instantly share code, notes, and snippets.

@yahyaKacem
Last active August 29, 2015 14:04
Show Gist options
  • Save yahyaKacem/041eef00e53028b1598f to your computer and use it in GitHub Desktop.
Save yahyaKacem/041eef00e53028b1598f to your computer and use it in GitHub Desktop.
make equal rows from a list
(function () {
inputList = [0, 1, 2, 3, 4, 5, 6, 7, 8];
ouputList = [];
makeRowsFromList = function makeRowsF(inputList, outputList, colsNum) {
var i, len;
outputList = outputList || [];
len = inputList.length;
for (i = 0; i < len; i += colsNum) {
outputList.push(inputList.slice(i, i + colsNum));
}
};
makeRowsFromList(intputList, outputList, 3);
}());
@yahyaKacem
Copy link
Author

Make equal rows from a list

just a simple function that takes a list like this:

[0, 1, 2, 3, 4, 5, 6, 7, 8]

And turn it into a list like this:

[[0, 1, 2], [3, 4, 5], [6, 7, 8]]

I made this to be used as a methode to group a list into equaly devided rows to be used with
bootstrap Grid system and AngularJS ngRepeat directive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment