Skip to content

Instantly share code, notes, and snippets.

@tripdog
Created June 19, 2021 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripdog/c465f5d48c94222901ba9cdbdbda9a8b to your computer and use it in GitHub Desktop.
Save tripdog/c465f5d48c94222901ba9cdbdbda9a8b to your computer and use it in GitHub Desktop.
Create a function called `wordReverse` that reverses a string using built-in JS methods

Create a function called wordReverse that reverses a string using built-in JS methods

const wordReverse = (string) => {
    return string.split("").reverse().join("")
}
console.log(wordReverse("This is how we do it."))

//.split creates an array=['T', 'h', 'i', 's', ' ',  'i', 's', ' ', 'h', 'o', 'w', ' ', 'w', 'e', ' ', 'd', 'o', ' ', 'i', 't', '.']
//.reverse simply reversese the array
//.join puts the elements of the string back together in a string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment