Mode entretien. Minuteur de 4 min, sans indices ni autocomplétion
First item
FacileTypeScript types4 min
Write a function first(items) that returns the first item of an array, or undefined if the array is empty. Do not change the array.
The result type must follow the array. For an array of numbers it is number | undefined, for an array of strings string | undefined. Replace unknown in the starter code. Do not change the code at the bottom, each line after @ts-expect-error must stay a type error.
Exemples
first([3, 1, 2])Renvoie 3
first(['a', 'b'])Renvoie 'a'
first([])Renvoie undefined
Fonction
Chargement de l'éditeur...
- Entrée
first([ 3, 1, 2 ])Attendu3 - Entrée
first([ 'a', 'b' ])Attendu'a' - Entrée
first([])
Les tests cachés se lancent à la soumission