Code Lab

Modo entrevista. Temporizador de 7 min, sin pistas y sin autocompletado

Remove by index

FácilArrays7 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.

Ejemplos

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

Devuelve [ 10, 30, 40 ]

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

Devuelve [ 1, 2, 3 ]

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

Devuelve [ 'a', 'b' ]

The array has no index -1.

Preguntada en Microsoft · Fuente

Cargando el editor…
  1. EntradaremoveAt([ 10, 20, 30, 40 ], 1)
    Esperado[ 10, 30, 40 ]
  2. EntradaremoveAt([ 1, 2, 3 ], 3)
    Esperado[ 1, 2, 3 ]
  3. EntradaremoveAt([ 'a', 'b' ], -1)
    Esperado[ 'a', 'b' ]
  4. The original array stays the same

Las pruebas ocultas se ejecutan al enviar