How to reverse each word in a string with Node.js

1 Answer

0 votes
function reverseEachWordInString(s) {
    let words = s.split(" ");
     
    let reversedWords = words.map(word => word.split("").reverse().join(""));
 
    return reversedWords.join(" ");
}
 
const s = "node.js c++ rust python c#";
 
console.log(reverseEachWordInString(s));
 
 
      
/*
run:
        
sj.edon ++c tsur nohtyp #c
        
*/

 



answered Aug 30, 2024 by avibootz

Related questions

1 answer 107 views
1 answer 137 views
1 answer 115 views
1 answer 114 views
1 answer 153 views
...