Return to Snippet

Revision: 28091
at June 30, 2010 19:44 by hand4ever


Updated Code
Array.prototype.each = function(fn){
	return this.length? [fn(this[0])].concat(this.slice(1).each(fn)): [];
};
//e.g.
var arr = [1,2,3,4].each(function(x){return x*2;});
//alert(arr);//[2,3,6,8]

Revision: 28090
at June 30, 2010 19:42 by hand4ever


Initial Code
Array.prototype.each = function(fn){
		return this.length? [fn(this[0])].concat(this.slice(1).each(fn)): [];
	};
        //e.g.
	var arr = [1,2,3,4].each(function(x){return x*2;});
	//alert(arr);//[2,3,6,8]

Initial URL

                                

Initial Description
each in Array,It can operate each element in Array.
e.g.
var result = [1,2,3,4].each(function(x){return Math.sqrt(x);});
//it return sqrt in [1,2,3,4]'s each item

Initial Title
currying in javascript

Initial Tags
javascript

Initial Language
JavaScript