The Section Cutter

Medium+25 XP

Mission Briefing

The Royal Chef needs exactly the first three ingredients from a massive, endless conveyor belt. You must build a mechanical blade to cut this exact section without damaging the rest!

The Concept: Slicing Arrays

The .slice(start, end) method copies a portion of an array into a brand new array.

  • It does not mutate the original array.
  • The item at the end index is not included in the copy. Example: [10, 20, 30, 40].slice(0, 2) // Returns [10, 20]

The Objective

Your function receives an array data (which will always have at least 3 items).

  1. Isolate and copy the first three elements into a new array.
  2. Return that new sliced array.

01EXAMPLE 1

Inputdata = [1, 2, 3, 4, 5]
Output[1, 2, 3]

Constraints

  • Use .slice(0, 3).
CoreArraysMethods
JavaScript
Loading...
3 Hidden

Input Arguments

data[1,2,3,4,5]

Expected Output

[1,2,3]

Click RUN to test your solution