From ba9dbeef3940bab3755af251d93a051fc41d0282 Mon Sep 17 00:00:00 2001
From: Angelos Chalaris n, to get the first element of the array.
Use Array.length = 0 to mutate the passed in array by resetting it's length to zero and Array.push() to re-populate it with only the pulled values.
(For a snippet that does not mutate the original array see without)
const pull = (arr, ...args) => {
- let pulled = arr.filter((v, i) => !args.toString().split(',').includes(v));
- arr.length = 0; pulled.forEach(v => arr.push(v));
+ let argState = Array.isArray(args[0]) ? args[0] : args;
+ let pulled = arr.filter((v, i) => !argState.includes(v));
+ arr.length = 0;
+ pulled.forEach(v => arr.push(v));
};
// let myArray1 = ['a', 'b', 'c', 'a', 'b', 'c'];