Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

105 lines
2.2 KiB
Markdown

---
id: a39963a4c10bc8b4d4f06d7e
title: Seek and Destroy
challengeType: 1
forumTopicId: 16046
dashedName: 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. Remove all elements from the initial array that are of the same value as these 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)` should return `[1, 1]`.
```js
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]`.
```js
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]`.
```js
assert.deepEqual(destroyer([3, 5, 1, 2, 2], 2, 3, 5), [1]);
```
`destroyer([2, 3, 2, 3], 2, 3)` should return `[]`.
```js
assert.deepEqual(destroyer([2, 3, 2, 3], 2, 3), []);
```
`destroyer(["tree", "hamburger", 53], "tree", 53)` should return `["hamburger"]`.
```js
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]`.
```js
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--
```js
function destroyer(arr) {
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
```
# --solutions--
```js
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);
```