Mode entretien. Minuteur de 10 min, sans indices ni autocomplétion
Print how often every digit occurs
MoyenMap and Set10 min
Write a function printDigitCounts(digits) that prints how many times every digit occurs in an array.
digitsis an array of whole numbers from0to9. It can be empty.- Print one line per digit with console log, in the format
<digit>: <count>, for example1: 2. - Print the lines after you have counted everything, one line per digit, not one line per array element.
- The lines go in the order in which each digit first appears in the array: its insertion order.
- For an empty array print nothing.
- The function returns nothing.
- The interviewer asked you to count with a Map. The tests check only the output; keep to the rule yourself.
Exemples
printDigitCounts([1, 0, 0, 1, 3, 5])Affiche 1: 2 | 0: 2 | 3: 1 | 5: 1
printDigitCounts([7, 7, 7])Affiche 7: 3
Posé chez Capgemini · Source
Chargement de l'éditeur...
- Entrée
printDigitCounts([ 1, 0, 0, 1, 3, 5 ])Sortie1: 2 0: 2 3: 1 5: 1 - Entrée
printDigitCounts([ 4, 2, 4 ])Sortie4: 2 2: 1
Les tests cachés se lancent à la soumission