Open Ge-yuan-jun opened 7 years ago
Given an input string, reverse the string word by word.
For example, Given s = "the sky is blue", return "blue is sky the"
"the sky is blue"
"blue is sky the"
/** * @param {string} str * @returns {string} */ var reverseWords = function(str) { return str.replace(/ +/ig,' ').replace(/^ /,'').split(' ').reverse().join(' ').replace(/ ?/,''); };
Given an input string, reverse the string word by word.
For example, Given s =
"the sky is blue"
, return"blue is sky the"