From 1c0d5c9a656d6bda6b7009f13cae0f546fae6d46 Mon Sep 17 00:00:00 2001 From: tjcrowder Date: Mon, 7 Sep 2009 15:30:47 +0100 Subject: [PATCH] doc: merged old docs for Enumerable#inGroupsOf. --- src/lang/enumerable.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/lang/enumerable.js b/src/lang/enumerable.js index cca54de..158772c 100644 --- a/src/lang/enumerable.js +++ b/src/lang/enumerable.js @@ -384,10 +384,30 @@ var Enumerable = (function() { } /** - * Enumerable#inGroupsOf(size[, filler = null]) -> [group...] + * Enumerable#inGroupsOf(number[, fillWith = null]) -> [group...] + * - number (Number): The number of items to include in each group. + * - fillWith (Object): An optional filler to use if the last group needs + * any; defaults to `null`. * - * Groups items in fixed-size chunks, using a specific value to fill up - * the last chunk if necessary. + * Like [[Enumerable#eachSlice]], but pads out the last chunk with the + * specified value if necessary and doesn't support the `iterator` function. + * + * ### Examples + * + * var students = [ + * { name: 'Sunny', age: 20 }, + * { name: 'Audrey', age: 21 }, + * { name: 'Matt', age: 20 }, + * { name: 'Amelie', age: 26 }, + * { name: 'Will', age: 21 } + * ]; + * + * students.inGroupsOf(2, { name: '', age: 0 }); + * // -> [ + * // [{ name: 'Sunny', age: 20 }, { name: 'Audrey', age: 21 }], + * // [{ name: 'Matt', age: 20 }, { name: 'Amelie', age: 26 }], + * // [{ name: 'Will', age: 21 }, { name: '', age: 0 }] + * // ] **/ function inGroupsOf(number, fillWith) { fillWith = Object.isUndefined(fillWith) ? null : fillWith;