Mode entretien. Minuteur de 5 min, sans indices ni autocomplétion
Every second number from the end
FacileBasics5 min
Write a function everySecondFromEnd(numbers) that goes through an array from the end and takes every second element.
numbersis an array of integers. It can be empty.- Return a new array: first the last element, then the third from the end, then the fifth from the end, and so on.
- Do not change
numbers: after the call it must have the same elements in the same order. - For an empty array return
[].
Exemples
everySecondFromEnd([1, 10, 24, 17, 82, 40, 12, 8412, 81212, 93, 9, 13, 46])Renvoie [ 46, 9, 81212, 12, 82, 24, 1 ]
everySecondFromEnd([1, 2, 3, 4])Renvoie [ 4, 2 ]
Posé chez Capgemini · Source
Chargement de l'éditeur...
- Entrée
everySecondFromEnd([ 1, 10, 24, 17, 82, 40, 12, 8412, 81212, 93, 9, 13, 46 ])Attendu[ 46, 9, 81212, 12, 82, 24, 1 ] - Entrée
everySecondFromEnd([ 1, 2, 3, 4 ])Attendu[ 4, 2 ] - Entrée
everySecondFromEnd([])Attendu[] - The input array is not changed, the result is a new array
Les tests cachés se lancent à la soumission