Code Lab

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

First non-repeating character

MediaMap 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.

Ejemplos

firstUniqueChar('swiss')

Devuelve 'w'

firstUniqueChar('aabb')

Devuelve null

firstUniqueChar('aA')

Devuelve 'a'

Fuente

Cargando el editor…
  1. EntradafirstUniqueChar('swiss')
    Esperado'w'
  2. EntradafirstUniqueChar('aabb')
    Esperadonull
  3. EntradafirstUniqueChar('aA')
    Esperado'a'

Las pruebas ocultas se ejecutan al enviar