Hello - I think I know how to solve this… but in just starting out… i tried looking at arr[0]… I get a print out of 1. Rather than I thought I would get returned the whole first array which is what I think is in arr[0]… arr[1] returns 2 as expected.
Why would arr[0] not return [1, 2, 3, 1, 2, 3] ?
thanks,
Brett
Your code so far
function destroyer(arr) {
// Remove all the values
var destroy = [];
console.log(JSON.stringify(arr[0]));
var search = arr.slice(1);
console.log(search);
arr.filter(element => {
});
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_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.
I’m not sure I understand what you mean with the whole “first” array comment, you only pass one array as a parameter when you call the function. If you do this:
I mean no offense, but you are trying to solve the Seek and Destroy intermediate algorithm and you don’t know why console.log(arr[0]) will not print the whole array? This is a very basic concept, I don’t think one would be ready to solve the basic algorithms w/o knowing that, let alone the intermediate ones. Again, I apologize if I come off as rude, but it’s weird that you are trying to solve the intermediate algorithms without knowing such core concept.
In any case, if you want to use the whole array just arr would do.
Oh I see what you are confused about. In this case you only have one array which is [1, 2, 3, 1, 2, 3] the 2,3 are a number of arguments that you are passing when executing the function, it could be 1 or 10 arguments, etc, in this case you are passing only 2 arguments besides the array.
You can try this function destroyer(arr, ...args) { console.log(args) }, by doing this you will have all the arguments that you passed when you call the function in an array.
It is a single argument, as such arr, which is the first parameter of the function, is that array. You are not using the other parameters in the function
Check the difference between arr and the object arguments, print both of them and you will see
the function has only one parameter, so the first argument passed in the function is stored in that parameter, the others are not. You can access the other parameters through the arguments object, or through a second parameter with the rest operator as shown by @Gilbert1391