Names with a score above 9
MediumMap 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.
entriesis 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
Mapis strictly greater than9. A score of exactly9does 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. The tests check only the result; keep to the rule yourself.
Examples
namesAboveNine([['Sachin', 9.2], ['Isha', 7.6]])Returns [ 'Sachin' ]
namesAboveNine([['Isha', 7.6], ['Sachin', 9.2], ['Isha', 9.9]])Returns [ 'Isha', 'Sachin' ]
namesAboveNine([])Returns []
Asked at EPAM · Source
Loading the editor...
- Input
namesAboveNine([ [ 'Sachin', 9.2 ], [ 'Isha', 7.6 ] ])Expected[ 'Sachin' ] - Input
namesAboveNine([ [ 'Ann', 9.5 ], [ 'Bob', 10 ], [ 'Cid', 3 ] ])Expected[ 'Ann', 'Bob' ]
Hidden tests run on Submit