Tell us what’s happening:
Describe your issue in detail here.
Your code so far?
can someone please what line 8 and 9 are for?
function nonMutatingSplice(cities) {
// Only change code below this line
return cities.slice(0, 3);
// Only change code above this line
}
const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
nonMutatingSplice(inputCities);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Challenge: Functional Programming - Remove Elements from an Array Using slice Instead of splice
The ‘cities’ is the name of the function’s argument, which is defined at the time of the function declaration. You can pass any variable, even another function as an argument to that function, and it actually “becomes” ‘cities’ for that particular case.
I understand that cities is the name of the functions argument.
I also understand that you can pass a function on to another functions parameter.
I don’t understand how cities knows it’s an array named inputCities. and that it will .slice this array named something different.
I’m used to seeing an array and then having to slice or splice it… this lessons syntax is confusing me.
The ‘cities’ doesn’t know anything. It is some named argument and may be named as you wish, as long as the statement in the function uses that argument to produce, or return something: