← Back to challenges

Reverse Sort: Lexical and Length

JavaScriptHardsortingstrings

Instructions

Write a function that sorts the words in a given string lexicographically (lexical sort) and by length in reverse order.

Examples

reverseSort("You've rocked the pragmatic world in the making!")
 ➞ "pragmatic making! You've rocked world the the in"

reverseSort("Tesh makes my world worth enjoying and living for.")
 ➞ "enjoying living worth world makes Tesh for. and my"

reverseSort("Shaken by the bloody truth and crazy lies.")
 ➞ "Shaken bloody truth lies. crazy the and by"

reverseSort("Java streams and collections are fun to program with!")
 ➞ "collections streams program with! Java fun are and to"

Notes

  • Special characters, punctuation marks and symbols are part of the word that directly precedes it.
  • The space character separates each word in the given string.
  • Case insensitive sorting is required.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.