Last active
September 3, 2023 10:51
-
-
Save ChousinRahit/d027fff3e1ab569c9218a0eabe826c43 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
// Reverse Words in a String | |
// Given an input string, reverse the string word by word, the first word will be the last, and so on. | |
// Examples | |
// reverseWords(" the sky is blue") ➞ "blue is sky the" | |
// reverseWords("hello world! ") ➞ "world! hello" | |
// reverseWords("a good example") ➞ "example good a" | |
// Pseudocode | |
// Write a function "reverseWords" that takes one string argument | |
// split the string with empty spaces | |
// reverse the array and join them | |
// resturn result | |
function reverseWords(str) { | |
return str.split(' ').reverse().join(' '); | |
} | |
console.log(reverseWords(' the sky is blue')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment