code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

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:41:20+05:18 · Edit