Re: [Proto-Scripty] Returning an array of results from an operation on an array.
On 17 September 2010 13:26, Jarkko Laine wrote: > > On 17.9.2010, at 15.03, Richard Quadling wrote: > >> Hi. >> >> How do I do something like this (just an example) ... >> >> [1,2,3].each(function(val){return val * val;}); >> >> such that the result is ... >> >> [1,4,9] > > [1,2,3].map(function(i){ return i * i }); // > http://api.prototypejs.org/language/enumerable/prototype/collect/ > > Note that invoke is a shorthand for map except that it calls a method for > each of the items: > > ['hello', 'world'].invoke('toUpperCase'); // > http://api.prototypejs.org/language/enumerable/prototype/invoke/ > // -> ['HELLO', 'WORLD'] > > Cheers, > //jarkko .map() ARGHH!! Wood 4 trees -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] Returning an array of results from an operation on an array.
On 17.9.2010, at 15.03, Richard Quadling wrote: > Hi. > > How do I do something like this (just an example) ... > > [1,2,3].each(function(val){return val * val;}); > > such that the result is ... > > [1,4,9] [1,2,3].map(function(i){ return i * i }); // http://api.prototypejs.org/language/enumerable/prototype/collect/ Note that invoke is a shorthand for map except that it calls a method for each of the items: ['hello', 'world'].invoke('toUpperCase'); // http://api.prototypejs.org/language/enumerable/prototype/invoke/ // -> ['HELLO', 'WORLD'] Cheers, //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://odesign.fi Check out my latest book, Unobtrusive Prototype, fresh off the Peepcode oven: http://peepcode.com/products/unobtrusive-prototype-js -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.