nice article
I wanted to add, you can also use reduce for the last example
const originalArray = [4, 6, 8, 10, 8, 12, 6, 45, 8,9,11];
originalArray.reduce((acc,number,index,arr)=>{
if(number>5) acc.push(number);
// that way we can exit the reduce
if(acc.length===3) arr.splice(index+1);
return acc
},[])
just need to be aware that the arr.splice is actually mutating the original array
we can slice the original array to create a shadow copy and don't mutate the original array, but not sure about the perfomance
originalArray.slice().reduce ...