8月 28 2017 Programming Language►JavaScript [JavaScript] forEach, map, reduce 實作 前言紀錄一下內建函式的實作。 forEach12345Array.prototype.forEach = function(fn){ for ( var i = 0; i < this.length; i ++ ){ fn(this[i], i); }} map1234567Array.prototype.map = function(fn){ var newArray = []; for ( var i = 0; i < this.length ; i++ ){ newArray.push(fn(this[i], i)); } return newArray;} reduce12345678Array.prototype.reduce = function(fn, initValue){ var result = initValue || this[0] ; var initIndex = initValue ? 0 : 1; for ( var i = initIndex; i < this.length; i ++ ){ result = fn(result, this[i], i); } return result;} Newer [Phoenix] Socket Server Older [Pwnable.kr] fd