code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

12 Seek Destroy

/**
 * Created by Ashish Patel
 * Copyright © 2017 ashish.me
 * ashishsushilpatel@gmail.com
 */

/**
 * Problem:
 * 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.
 */

function destroyer(...args) {
    const itemsToRemove = Array.from(args).slice(1);
    return args[0].filter(item => {
        return !itemsToRemove.includes(item);
    });
}

console.log(destroyer([1, 2, 3, 1, 2, 3], 2, 3));

Created 2019-11-24T04:53:20+05:30 · Edit