Files
2023-09-05 23:29:50 +05:30

2.2 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
a39963a4c10bc8b4d4f06d7e Procurar e destruir 1 16046 seek-and-destroy

--description--

Você receberá um array inicial como primeiro argumento da função destroyer, seguido por um ou mais argumentos. Remova todos os elementos da matriz inicial que são do mesmo valor que esses argumentos.

A função deve aceitar um número indeterminado de argumentos. Em outras palavras, ela deve ser uma função variádica. Você poderá acessar os argumentos adicionais colocando um parâmetro rest na definição da função ou usando o objeto arguments.

--hints--

destroyer([1, 2, 3, 1, 2, 3], 2, 3) deve retornar [1, 1].

assert.deepEqual(destroyer([1, 2, 3, 1, 2, 3], 2, 3), [1, 1]);

destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3) deve retornar [1, 5, 1].

assert.deepEqual(destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3), [1, 5, 1]);

destroyer([3, 5, 1, 2, 2], 2, 3, 5) deve retornar [1].

assert.deepEqual(destroyer([3, 5, 1, 2, 2], 2, 3, 5), [1]);

destroyer([2, 3, 2, 3], 2, 3) deve retornar [].

assert.deepEqual(destroyer([2, 3, 2, 3], 2, 3), []);

destroyer(["tree", "hamburger", 53], "tree", 53) deve retornar ["hamburger"].

assert.deepEqual(destroyer(['tree', 'hamburger', 53], 'tree', 53), [
  'hamburger'
]);

destroyer(["possum", "trollo", 12, "safari", "hotdog", 92, 65, "grandma", "bugati", "trojan", "yacht"], "yacht", "possum", "trollo", "safari", "hotdog", "grandma", "bugati", "trojan") deve retornar [12,92,65].

assert.deepEqual(
  destroyer(
    [
      'possum',
      'trollo',
      12,
      'safari',
      'hotdog',
      92,
      65,
      'grandma',
      'bugati',
      'trojan',
      'yacht'
    ],
    'yacht',
    'possum',
    'trollo',
    'safari',
    'hotdog',
    'grandma',
    'bugati',
    'trojan'
  ),
  [12, 92, 65]
);

--seed--

--seed-contents--

function destroyer(arr) {
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

--solutions--

function destroyer(arr) {
  var hash = Object.create(null);
  [].slice.call(arguments, 1).forEach(function(e) {
    hash[e] = true;
  });
  return arr.filter(function(e) { return !(e in hash);});
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);