Code Lab

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

First non-repeating character

MoyenMap and Set10 min

Write a function firstUniqueChar(text) that returns the first character of the string text that appears in it exactly once. If there is no such character, return null.

  • "First" means the leftmost in text: in 'swiss' the answer is 'w'.
  • Letter case matters: 'a' and 'A' are different characters.
  • Every character counts, also spaces, digits and punctuation.
  • An emoji such as 🐞 is one character. Return it whole, not half of it.
  • An empty string gives null.

Exemples

firstUniqueChar('swiss')

Renvoie 'w'

firstUniqueChar('aabb')

Renvoie null

firstUniqueChar('aA')

Renvoie 'a'

Source

Chargement de l'éditeur...
  1. EntréefirstUniqueChar('swiss')
    Attendu'w'
  2. EntréefirstUniqueChar('aabb')
    Attendunull
  3. EntréefirstUniqueChar('aA')
    Attendu'a'

Les tests cachés se lancent à la soumission