1// hey buddy, here are different implementations, choose your favourite !!
2
3// Examples
4// "This is an example!" ==> "sihT si na !elpmaxe"
5// "double spaces" ==> "elbuod secaps"
6
7function reverseWords(str) {
8 const allWords = str.split(" ")
9 return allWords.map(item => item.split("").reverse().join("")).join(" ")
10}
11
12
13function reverseWords(str) {
14 return str
15 .split(" ")
16 .map(word => {
17 return word.split("").reverse().join("")
18 })
19 .join(" ")
20}
21
22
23var reverseWords = s => s.replace(/\S+/g, v => [...v].reverse().join``)
1function reverseString(str) {
2 return str.split("").reverse().join("");
3}
4reverseString("hello");
1function reverseWords(str) {
2 const allWords = str.split(" ")
3 return allWords.map(item => item.split("").reverse().join("")).join(" ")
4}
1str.split('').reduce((reversed, character) =>{
2 return character + reversed;
3 }, '');
4//apple = leppa