Good morning, everyone.
Let's warm up for the start of the week by playing with strings.
s'yadoT egnellahc semoc from user xDranik on sraWedoC!
Write a function that takes in a string of one or more words and returns the same string, but with all words with five letters or more reversed. Strings passed in will consist of only letters and spaces.
Be sure to keep the order of the words the same and only reverse the letters.
Good luck, yppaH gniedoc!
Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge for a future post? Email yo+challenge@dev.to with your suggestions!
Latest comments (23)
function spinWords(string){
return string.split(' ').map(function(string){
return (string.length > 4) ? string.split('').reverse().join('') : string
}).join(' ');
}
My solution in js
Ruby
Tests
Results
Haskell:
PHP 5.3.0 to 7.3.x:
PHP >= 7.4:
Python 3 : :P
s='yadoT egnellahc semoc from user xDranik on sraWedoC!'
print(s[::-1])
Rust, sort of in place
The rest of the story below the fold:
JS/ES
Elixir:
A quick one in C#