美文网首页
reduce实现map

reduce实现map

作者: Time_Notes | 来源:发表于2020-07-12 18:27 被阅读0次

    Array.prototype.map = function (callback) {

        var arr = this;

        return arr.reduce((acc, cur, i) => {

            acc.push(callback(cur, i, arr));

            return acc

        }, []);

    }


    var m = [1,2,3,4,54].map(function (v, i, arr) {

        return v * v

    });

    console.log(m)

    相关文章

      网友评论

          本文标题:reduce实现map

          本文链接:https://www.haomeiwen.com/subject/sjaknhtx.html