This one almost stumped me ngl lol
Dart
String smsShortener(String message) { if(message.length <= 160) return message; List<String> spaces = message.split(" "); var result = message; for(var idx = spaces.length-1; idx > 0; idx--) { var start = spaces.take(idx).join(" "); var end = spaces.skip(idx).map((word) => "${word[0].toUpperCase()}${word.substring(1)}").join(""); result = "$start$end"; if(result.length <= 160) return result; } return result.substring(0, 160); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This one almost stumped me ngl lol
Dart