inGroupsOf

inGroupsOf(size[, filler = null]) -> [group...]

Groups items in fixed-size chunks, using a specific value to fill up the last chunk if necessary.

Example


var students = [
  { name: 'Sunny', age: 20 },  { name: 'Audrey', age: 21 },
  { name: 'Matt', age: 20 },   { name: 'Élodie', age: 26 },
  { name: 'Will', age: 21 },   { name: 'David', age: 23 },
  { name: 'Julien', age: 22 }, { name: 'Thomas', age: 21 },
  { name: 'Serpil', age: 22 }
];

students.pluck('name').inGroupsOf(4) {
// -> [ ['Sunny', 'Audrey', 'Matt', 'Élodie'],
//      ['Will', 'David', 'Julien', 'Thomas'],
//      ['Serpil', null, null, null] ]

See also

There is a variant called eachSlice, which does not fill up the last group to size.