Comment by jaredcheeda on 18/12/2024 at 03:27 UTC*

-1 upvotes, 1 direct replies (showing 1)

View submission: Completely lost at what is happening here

Naive approach would be:

function removeFromArray (include, ...exclude) {
  return include.filter(function (item) {
    return !exclude.includes(item);
  });
}

But the right answer is to use a well tested and popular library. Lodash will do this for you. If you are doing this for work, use lodash. If you are doing this for a side project, use lodash. If you are doing this to learn how to code, then you should do it yourself.

<script src="https://cdn.jsdelivr.net/npm/lodash.xor@4.5.0/index.min.js"></script>
<script>
function removeFromArray (include, ...exclude) {
  return xor(include, exclude);
}
</script>

Replies

Comment by Brianvm1987 at 18/12/2024 at 03:41 UTC

2 upvotes, 0 direct replies

I'll definitely look into this. Thanks!