Write a reverseWords
function that accepts a string a parameter, and reverses each word in the string. Every space should stay, so you cannot usewords
from Prelude
.
Example:
reverseWords("This is an example!"); // returns "sihT si na !elpmaxe"
function reverseWords(str) { return str.split(‘ ‘).map(x=>x.split(‘‘).reverse().join(‘‘)).join(‘ ‘); }
时间: 2024-10-21 02:57:37