Javascript Array myInject(callback, acc)

Description

Javascript Array myInject(callback, acc)


Array.prototype.myInject = function(callback, acc) {
  // if (acc === undefined){
  //   acc = array.shift();
  // }//w w w . jav a  2s.  com
  this.myEach((el) => {acc = callback(acc, el);});
  return acc;
};

console.log([1, 2, 3, 4].myInject( (a, b) => a + b   , 0))



PreviousNext

Related