map by reduce

by Artem

JavaScript

'use strict';

Object.defineProperty(Array.prototype, 'mapp', {
  value: function(func) {
    return this.reduce((prev, item, idx, arr) => {
      prev.push(func.call(this, item, idx, arr));
      return prev;
    }, []);
  }
});

const arr = [4, 9, 16];

let newArr = arr.mapp(Math.sqrt);
console.log(newArr);