challenge 5

by Darby Rathbone

JavaScript

/* ------------------------------------------------------------------------------------------------
CHALLENGE 5

Write a function named removeWithAnon that produces the same output as challenges 3 and 4.

This function should use forEach again, but rather than taking in a callback as an argument, define an anonymous function as the argument to forEach.

This anonymous function should accept up to three arguments: the element, the index, and the array.
------------------------------------------------------------------------------------------------ */
const removeOne = (num, arr) => {
	if(num%3==2)
  {
  console.log(num,arr);
  	arr.pop();
  }
  return arr;
};
const removeWithAnon = (arr) => {
  let newarr = arr.slice();
  arr.forEach((e) => {
    newarr = removeOne(e, newarr);
  });
  return newarr;
}