Created
December 7, 2015 01:47
-
-
Save anonymous/e122b8536efca8083924 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/thetinybeaker 's solution for Bonfire: Reverse a String
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
// 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) | |
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