yinusxxxx

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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(' ');
}

 

posted on 2016-05-08 18:32  yinusxxxx  阅读(128)  评论(0编辑  收藏  举报