문제
You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
예시
destroyer([1, 2, 3, 1, 2, 3], 2, 3) should return [1, 1]. destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3) should return [1, 5, 1]. destroyer([3, 5, 1, 2, 2], 2, 3, 5) should return [1].
내가 푼 답
function destroyer(arr) { for(var i = 0 ; i < arguments.length ; i++) { if(!Array.isArray(arguments[i])) { for(var j = 0 ; j < arr.length ; j++) { if(arr[j] === arguments[i]) { arr.splice(j,1); j = j - 1 } } } } return arr; }
Advanced Solution 1
function destroyer(arr) { var args = Array.from(arguments).slice(1); return arr.filter(function(val) { return !args.includes(val); }); }
Advanced Solution 2
const destroyer = (arr, ...args) => arr.filter(i => !args.includes(i));