From adee4abe0c0e4f6a78207763e6504799cfc6e6ca Mon Sep 17 00:00:00 2001 From: tjcrowder Date: Mon, 7 Sep 2009 14:42:14 +0100 Subject: [PATCH] doc: merged old docs for enumerable#eachSlice --- src/lang/enumerable.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/lang/enumerable.js b/src/lang/enumerable.js index db4a09e..d5e5b37 100644 --- a/src/lang/enumerable.js +++ b/src/lang/enumerable.js @@ -120,11 +120,31 @@ var Enumerable = (function() { /** * Enumerable#eachSlice(number[, iterator = Prototype.K[, context]]) -> Enumerable + * - number (Number): The number of items to include in each slice. + * - iterator (Function): An optional function to use to transform each + * element before it's included in the slice; if this is not provided, + * the element itself is included. + * - context (Object): An optional object to use as `this` within + * calls to the iterator. * - * Groups items into chunks of the given size. - * The final "slice" may have fewer than `number` items; it won't "pad" the - * last group with empty values. For that behavior, use - * [[Enumerable#inGroupsOf]]. + * Groups items into chunks of the given size. The final "slice" may have + * fewer than `number` items; it won't "pad" the last group with empty + * values. For that behavior, use [[Enumerable#inGroupsOf]]. + * + * ### Example + * + * var students = [ + * { name: 'Sunny', age: 20 }, + * { name: 'Audrey', age: 21 }, + * { name: 'Matt', age: 20 }, + * { name: 'Amelie', age: 26 }, + * { name: 'Will', age: 21 } + * ]; + * + * students.eachSlice(3, function(student) { + * return student.name; + * }); + * // -> [['Sunny', 'Audrey', 'Matt'], ['Amelie', 'Will']] **/ function eachSlice(number, iterator, context) { var index = -number, slices = [], array = this.toArray();