challenge 4

by Darby Rathbone

JavaScript

/* ------------------------------------------------------------------------------------------------
CHALLENGE 4

Write a function named removeWithForEach that produces the same output as challenge 3, but uses forEach.
------------------------------------------------------------------------------------------------ */

const removeWithForEach = (arr, callback) => {
  let newarr = arr.slice();
  arr.forEach((e) => {
    newarr = callback(e, newarr);
  });
  return newarr;
}