Code Lab

Mode entretien. Minuteur de 7 min, sans indices ni autocomplétion

Remove by index

FacileArrays7 min

Write a function removeAt(items, index) that returns a new array without the element at index index. Do not change the original array and do not use splice. If the array has no such index, return an unchanged copy of it.

Exemples

removeAt([10, 20, 30, 40], 1)

Renvoie [ 10, 30, 40 ]

removeAt([1, 2, 3], 3)

Renvoie [ 1, 2, 3 ]

The indexes here are 0, 1 and 2.
removeAt(['a', 'b'], -1)

Renvoie [ 'a', 'b' ]

The array has no index -1.

Posé chez Microsoft · Source

Chargement de l'éditeur...
  1. EntréeremoveAt([ 10, 20, 30, 40 ], 1)
    Attendu[ 10, 30, 40 ]
  2. EntréeremoveAt([ 1, 2, 3 ], 3)
    Attendu[ 1, 2, 3 ]
  3. EntréeremoveAt([ 'a', 'b' ], -1)
    Attendu[ 'a', 'b' ]
  4. The original array stays the same

Les tests cachés se lancent à la soumission