Modo entrevista. Cronômetro de 7 min, sem dicas e sem autocompletar
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.
Exemplos
removeAt([10, 20, 30, 40], 1)Retorna [ 10, 30, 40 ]
removeAt([1, 2, 3], 3)Retorna [ 1, 2, 3 ]
removeAt(['a', 'b'], -1)Retorna [ 'a', 'b' ]
Cobrada em Microsoft · Fonte
Carregando o editor...
- Entrada
removeAt([ 10, 20, 30, 40 ], 1)Esperado[ 10, 30, 40 ] - Entrada
removeAt([ 1, 2, 3 ], 3)Esperado[ 1, 2, 3 ] - Entrada
removeAt([ 'a', 'b' ], -1)Esperado[ 'a', 'b' ] - The original array stays the same
Os testes ocultos rodam no envio