Skip to content

Commit

Permalink
Reverses each word in sentence
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesCreativeContent authored May 12, 2020
1 parent d576fad commit a32cc5a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions reverseEachWord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example 1:
Input: "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"
Note: In the string, each word is separated by single space and there will not be any extra space in the string.
*/

//Answer//
/**
* @param {string} s
* @return {string}
*/
var reverseWords = function(s) {
return s.split('').reverse().join('').split(' ').reverse().join(' ')
};exercise

0 comments on commit a32cc5a

Please sign in to comment.