Remove Elements from an Array Using slice Instead of splice challenge

why (0,3) when i am supposed to return only 3 cities??
Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

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);
console.log(inputCities)
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0

Challenge: Remove Elements from an Array Using slice Instead of splice

Link to the challenge:

Hi @columbuschidozie1 !

Take a close look at the docs for the slice method.

Carefully read through the explanation for the optional end parameter from the docs.

Zero-based index before which to end extraction. slice extracts up to but not including end . For example, slice(1,4) extracts the second element through the fourth element (elements indexed 1, 2, and 3).

So in your case here

the slice method will start and index 0 and include 1 and 2 but not 3.

Also, this console.log is just returning the original array

But remember that slice creates a new array.
If you want to see your results in the console, place the console.log inside your function.

console.log(cities.slice(0, 3))

Hi jessica. i am really having a hard time to understand reduce. can you put me through on the challenge.after watching mosh reduce tutorial, i still could not solve the challenge. https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.