Created
March 12, 2023 04:43
-
-
Save pjcodesjs/898d1604a7193e2c8234a529c7f2efc8 to your computer and use it in GitHub Desktop.
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
function reverseWords(str) { | |
// Split the string into an array of words | |
const wordsArr = str.split(' '); | |
// Reverse the order of the words in the array | |
const reversedWordsArr = wordsArr.reverse(); | |
// Join the reversed array back into a string | |
const reversedStr = reversedWordsArr.join(' '); | |
return reversedStr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment