Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 5, 2020 02:55 pm GMT

Daily Challenge 253 - Sort Sentences Pseudo-alphabetically

Given a standard English sentence passed as a string, write a method that will return that sentence but with the words sorted by first letter.

All words that begin with a lower case letter should be at the beginning of the sorted sentence, and sorted in ascending order. All words that begin with an upper case letter should come after that, and should be sorted in descending order.

If a word appears multiple times in the sentence, it should be returned multiple times. Any punctuation can be discarded.

Example
input: "Land of the Old Thirteen! Massachusetts land! land of Vermont and Connecticut!"
return: "and land land of of the Vermont Thirteen Old Massachusetts Land Connecticut"
Lower case letters are sorted a -> l -> l -> o -> o -> t
Upper case letters are sorted V -> T -> O -> M -> L -> C.

Tests
sort("take up the task eternal, and the burden and the lesson")
sort("Pioneers, O Pioneers!")

Good luck!

This challenge comes from Daremyth on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge idea for a future post? Email [email protected] with your suggestions!


Original Link: https://dev.to/thepracticaldev/daily-challenge-253-sort-sentences-pseudo-alphabetically-4nk1

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To