Mode entretien. Minuteur de 10 min, sans indices ni autocomplétion
Remove the spaces and sort
MoyenStrings10 min
Write a function sortCharacters(text) that removes all whitespace from the string text and returns the other characters sorted.
texthas only ASCII characters: letters, digits, punctuation and whitespace.- Whitespace is a space, a tab
\tand a line break\nor\r. All of it goes, not only spaces. - Each character is sorted by its character code, from small to large. This is the order of sort without a compare function. For example,
!and,come before the digits, the digits come before the capital letters, and the capital letters come before the small letters. So'Z'comes before'a'. - Repeated characters stay:
'banana'gives'aaabnn'. - Return a string. An empty string or a string of only whitespace gives
''.
Exemples
sortCharacters('My Name is Nikhil')Renvoie 'MNNaehiiiklmsy'
sortCharacters('Zebra 123')Renvoie '123Zaber'
Posé chez Cognizant · Source
Chargement de l'éditeur...
- Entrée
sortCharacters('My Name is Nikhil')Attendu'MNNaehiiiklmsy' - Entrée
sortCharacters('b a')Attendu'ab'
Les tests cachés se lancent à la soumission