function dropElements(arr, func) {
let output = arr.reduce((acc=[], elem) => {
if (func(elem)){
acc.push(arr.slice(arr.indexOf(elem)))
return acc
}
}, [])
return output
}
let tester = dropElements([1, 2, 3, 4,5,6,3,2,1], function(n) {return n >= 3;})
console.log(tester)
The desired outcome is to have an array [3,4,5,6,3,2,1] as the result. However, instead of that, it is generating arrays with decreasing copy sizes.
Essentially, the problem aims at going through the given array 'arr' and gradually removing elements from the beginning until the function 'func' returns true for a specific element during iteration.