Use of array.map with a function with three parameters in Javascript

It is needed to call func for num times inside Array.map callback as follows.

const feedback = (array, func, num) => {
  return array.map((item) => {
    let val = func(item);
    for (let i = 0; i < num - 1; i ++) {
      val = func(val);
    }
    return val;
  });
}

// Helper function
function double(element) {
  return element * 2;
}

console.log(feedback([1,2,3], double, 2));

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top