Oliver Eyton-Williams 0bd52f8bd1
Feat: add new Markdown parser (#39800)
and change all the challenges to new `md` format.
2020-11-27 10:02:05 -08:00

2.0 KiB

id, title, challengeType, forumTopicId
id title challengeType forumTopicId
a39963a4c10bc8b4d4f06d7e Seek and Destroy 5 16046

--description--

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.

Note
You have to use the arguments object.

--hints--

destroyer([1, 2, 3, 1, 2, 3], 2, 3) should return [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) should return [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) should return [1].

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

destroyer([2, 3, 2, 3], 2, 3) should return [].

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

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