Skip to content

Instantly share code, notes, and snippets.

@pjcodesjs
Created March 12, 2023 04:43
Show Gist options
  • Save pjcodesjs/898d1604a7193e2c8234a529c7f2efc8 to your computer and use it in GitHub Desktop.
Save pjcodesjs/898d1604a7193e2c8234a529c7f2efc8 to your computer and use it in GitHub Desktop.
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