Created
February 23, 2023 09:54
-
-
Save mihailgaberov/1afd0df5588c3d6457dc45da85e5c1b4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// This problem was asked by Google. | |
// Given a string of words delimited by spaces, reverse the words in string. For example, given "hello world here", return "here world hello" | |
// Follow-up: given a mutable string representation, can you perform this operation in-place? | |
const reverseWords = (str) => str.split(' ').reverse().join(' ') | |
console.log(reverseWords("hello world here") === "here world hello") // true | |
console.log(reverseWords("hello world here") === "hello world here") // false | |
console.log(reverseWords("who the hell are you") === "you are hell the who") // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment