Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jiyoon-koo/0be935473650ca6dba83 to your computer and use it in GitHub Desktop.
Save jiyoon-koo/0be935473650ca6dba83 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/thetinybeaker 's solution for Bonfire: Reverse a String
// Bonfire: Reverse a String
// Author: @thetinybeaker
// Challenge: http://www.freecodecamp.com/challenges/bonfire-reverse-a-string#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
/*
Reverse the provided string.
You may need to turn the string into an array before you can reverse it.
Your result must be a string.
*/
function reverseString(str) {
return str.split('').reverse().join('');
}
//.split('') splits each letter...'' indicates no space in between splits, and puts the string into an array
//[G,r,e,e,t,i,n,g,s, ,f,r,o,m, ,E,a,r,t,h]
//.reverse() reverses the order of the array
//[h,t,r,a,E, ,m,o,r,f, ,s,g,n,i,t,e,e,r,G]
//.join('') joins the words together for those with no space in between.
//[htraE morf sgniteerG]
reverseString("hello");
reverseString("Howdy");
reverseString("Greetings from Earth");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment