Tell us what’s happening:
I just have a quick question about this problem. I’m a bit confused as to how you should go about solving the problem when the arguments aren’t defined as parameters going into the function. Or I think I’m confused what the difference between an argument and a parameter is. like the function we are writing looks like it only takes in an array so how do we account for the other arguments being passed in. any clarification would help!
Your code so far
function destroyer(arr) {
console.log(arguments)
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36
.
Challenge: Seek and Destroy
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
ILM
January 24, 2021, 4:53pm
2
iangoodman:
console.log(arguments)
you may see that the arguments
object contains all the passed in arguments, if you use it you can access the others
there are other ways to count for a variable number of arguments(ex. rest parameter), for this challenge you need to use the arguments
object
ok thank you!
Can you see where I may be going wrong with my solution?
function destroyer(arr) {
var targets = Array.from(arguments).slice(1)
console.log(arr)
arr.filter(function(num){
return targets.indexOf(num) === -1
})
return arr;
}
ILM
January 24, 2021, 5:06pm
4
you are not changing arr
in any way, the filter
method returns a new array
moriel
January 24, 2021, 6:25pm
5
Hi!
My recommendations are:
use targets without slice(1) =>
let targets = [...arguments]
or:
let targets = Array.from(arguments);
Code the expected result as follows:
let result = arr.filter(num => !targets.includes(num));
after that:
return result;
There are also other solutions with the help of loops!
ILM
January 24, 2021, 6:31pm
6
in that case targets[0]
is the array, which is unnecessary to test against, and also wrong - it works because of how JavaScript is
system
Closed
July 26, 2021, 6:31am
7
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.