Setup
SMS messages are limited to 160 characters. It tends to be irritating, especially when freshly written message is 164 characters long. Implement a function to shorten the message to 160 characters, starting from the end, by replacing spaces with camelCase, as much as necessary.
Example
Original Message:
No one expects the Spanish Inquisition! Our chief weapon is surprise, fear and surprise; two chief weapons, fear, surprise, and ruthless efficiency! And that will be it.
Shortened Message:
No one expects the Spanish Inquisition! Our chief weapon is surprise, fear and surprise; two chief weapons, fear,Surprise,AndRuthlessEfficiency!AndThatWillBeIt.
Tests
"SMS messages are limited to 160 characters. It tends to be irritating, especially when freshly written message is 164 characters long. SMS messages are limited to 160 characters. It tends to be irritating, especially when freshly written message is 164 characters long."
"This message is already short enough!"
"ThereIsNoSpoonThereIsNoSpoonThereIsNoSpoonThereIsNoSpoonThereIsNoSpoonThereIsNoSpoonThereIsNoSpoonThereIsNoSpoonThereIsNoSpoonThereIsNoSpoonThereIsNoSpoonThereIsNoSpoonThereIsNoSpoon"
Good luck!
This challenge comes from Bugari 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 yo+challenge@dev.to with your suggestions!
Top comments (6)
js recursive
A recursive solution in JavaScript:
With comments:
This one almost stumped me ngl lol
Dart
in Python
Note the tricky case about a tweet that starts with a space but is truncated -- first letter, even following spaces and punctuation, should not be capitalized.
python solution
This one ended up being less readable, will give a compact version and expanded version with commentary. Once again, Ruby:
Explained version: