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

2.4 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
a39963a4c10bc8b4d4f06d7e 検索して破棄する 1 16046 seek-and-destroy

--description--

You will be provided with an initial array as the first argument to the destroyer function, followed by one or more arguments. これらの引数と同じ値を持つすべての要素を最初の配列から削除してください。

The function must accept an indeterminate number of arguments, also known as a variadic function. You can access the additional arguments by adding a rest parameter to the function definition or using the arguments object.

--hints--

destroyer([1, 2, 3, 1, 2, 3], 2, 3)[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)[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)[1] を返す必要があります。

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

destroyer([2, 3, 2, 3], 2, 3)[] を返す必要があります。

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

destroyer(["tree", "hamburger", 53], "tree", 53)["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")[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);