eggheadio-github / stack-overflow-copy-paste

Utility functions copy/pasted (and modified slightly) from Stack Overflow
441 stars 606 forks source link

Add 'removeElementFromArray' function #170

Closed Vinnu1 closed 6 years ago

Vinnu1 commented 6 years ago

I would like to submit a function which checks if an element exists in array and if so, remove it and return the rest.

kentcdodds commented 6 years ago

That sounds great!

Vinnu1 commented 6 years ago

function removeElementFromArray(arr, re) { let index = arr.indexOf(re); if( index > -1 ){ arr.splice(index, 1); return arr; } else{ return arr; } }

This is what I have in mind, feels okay?

kentcdodds commented 6 years ago

Looks great!