Last active
September 27, 2022 16:45
-
-
Save bhaireshm/c8a319b06b5fb69d1f50fe758f380311 to your computer and use it in GitHub Desktop.
Reverse a word, sentence or reverse each words in a sentence.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @param str: string without space | |
function reverseStr(str){ | |
return str.split('').reverse().join(''); | |
} | |
// @param sentence: pass a sentence. | |
function reverseEachWordInSentence(sentence){ | |
return sentence.split(' ').map(reverseStr).join(' '); | |
} | |
// @param sentence: pass a sentence. | |
function reverseSentence(s){ | |
return s.split(' ').reverse().join(' '); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment