forked from shaonkabir8/JavaScript-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseek-and-destroy.js
More file actions
23 lines (13 loc) · 1.02 KB
/
seek-and-destroy.js
File metadata and controls
23 lines (13 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
🔥 Intermediate Algorithm Scripting: Seek and Destroy
⚡ Instruction: Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching name and value pairs (second argument). Each name and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array.
🌏 Refference: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou
*/
function destroyer(arr) {
// grab Arguments Object except First one by converting into Array
const args = Array.from(arguments).slice(1);
// Check if the elements of our args are included in First args(Array) or not!
// If not includes, Return !
return arr.filter(item => !args.includes(item))
}
destroyer(["possum", "trollo", 12, "safari", "hotdog", 92, 65, "grandma", "bugati", "trojan", "yacht"], "yacht", "possum", "trollo", "safari", "hotdog", "grandma", "bugati", "trojan");