Code Lab

Modo entrevista. Cronômetro de 10 min, sem dicas e sem autocompletar

Names with a score above 9

MédiaMap and Set10 min

Write a function namesAboveNine(entries) that stores names and scores in a map and returns the names with a score greater than 9.

  • entries is an array of pairs [name, score]: the name is a string, the score is a number. A name can be any string, also one made of digits, like '7'. The array can be empty.
  • Put every pair into a Map: the name is the key, the score is the value.
  • A name can occur more than once. Then the later score replaces the earlier one, and the name keeps its place in the Map (the place of its first appearance).
  • Return an array of names whose score in the Map is strictly greater than 9. A score of exactly 9 does not count.
  • Every name is in the result at most once, in the order of the Map.
  • Return only the names, not the entries. You can filter the entries of the map by value.
  • The interviewer asked to store the data in a Map. A hidden test checks that your code puts the pairs into a Map with set or new Map(entries).

Exemplos

namesAboveNine([['Sachin', 9.2], ['Isha', 7.6]])

Retorna [ 'Sachin' ]

namesAboveNine([['Isha', 7.6], ['Sachin', 9.2], ['Isha', 9.9]])

Retorna [ 'Isha', 'Sachin' ]

Isha gets the new score 9.9 but keeps her first place.
namesAboveNine([])

Retorna []

Cobrada em EPAM · Fonte

Carregando o editor...
  1. EntradanamesAboveNine([ [ 'Sachin', 9.2 ], [ 'Isha', 7.6 ] ])
    Esperado[ 'Sachin' ]
  2. EntradanamesAboveNine([ [ 'Ann', 9.5 ], [ 'Bob', 10 ], [ 'Cid', 3 ] ])
    Esperado[ 'Ann', 'Bob' ]

Os testes ocultos rodam no envio