From f1c8c1e266ce062aeee4497cf5e698fee0c1fce8 Mon Sep 17 00:00:00 2001 From: tjcrowder Date: Mon, 7 Sep 2009 14:09:44 +0100 Subject: [PATCH] doc: merge and update old docs for Enumerable#collect --- src/lang/enumerable.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/lang/enumerable.js b/src/lang/enumerable.js index 97be1ef..51d2cb2 100644 --- a/src/lang/enumerable.js +++ b/src/lang/enumerable.js @@ -193,9 +193,26 @@ var Enumerable = (function() { /** * Enumerable#collect([iterator = Prototype.K[, context]]) -> Array + * - iterator (Function): The iterator function to apply to each element + * in the enumeration. + * - context (Object): An optional object to use as `this` within + * calls to the iterator. * - * Returns the results of applying the iterator to each element. - * Aliased as [[Enumerable#map]]. + * Returns the result of applying `iterator` to each element. If no + * `iterator` is provided, the elements are simply copied to the + * result array. + * + * ### Examples + * + * ['Hitch', "Hiker's", 'Guide', 'to', 'the', 'Galaxy'].collect(function(s) { + * return s.charAt(0).toUpperCase(); + * }) + * // -> ['H', 'H', 'G', 'T', 'T', 'G'] + * + * $R(1,5).collect(function(n) { + * return n * n; + * }) + * // -> [1, 4, 9, 16, 25] **/ function collect(iterator, context) { iterator = iterator || Prototype.K;