Javascript Array rawr(f)
// complete the implementation of triple and map such that // [0,3,6,9,12] is printed var arr = [0,1,2,3,4]; var triple = function(x) { return x * 3; }; Array.prototype.rawr = function(f) { var newArr =[]; /*from w w w .ja v a2 s . c o m*/ for (var i = 0; i < this.length; i++) { newArr.push(f(this[i])); } return newArr; }; var newArr = arr.rawr(triple); console.log(newArr); console.log("using map this time"); console.log(arr.map(triple));