JavaScript: curry, extend Array function
Blogs20142014-09-02
JavaScript: curry, extend Array function
Some JavaScript tips, interesting.
`//1. a curry function:function add(a) { if(arguments.length===2) return arguments[0] + arguments[1]; else return function(b) { return a + b; } }; add(8)(9) //17 add(6,7) //13
//2. a Array added function if(! Array.prototype.duplicate) { Array.prototype.duplicate = function() { return this.concat(this); } } [1,2,3,4,5].duplicate(); //[1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
//3. string - array String.prototype.isPalindrome = function(){ return this.split(”).reverse().join(”)===this.toString(); } ‘levels’.isPalindrome(); //false ‘level’.isPalindrome(); //true`
