Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2015 04:09
Show Gist options
  • Save anonymous/f7a35bde2d9cbe821775 to your computer and use it in GitHub Desktop.
Save anonymous/f7a35bde2d9cbe821775 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/mattnwa 's solution for Bonfire: Reverse a String
// Bonfire: Reverse a String
// Author: @mattnwa
// Challenge: http://www.freecodecamp.com/challenges/bonfire-reverse-a-string
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function reverseString(str) {
var result = str.split('').reverse();
return result.join('');
}
reverseString("hello");
@mattnwa
Copy link

mattnwa commented Dec 3, 2015

#1 Bonfire - Reversing a string.

1. Manipulating arrays are much easier.

2. After splitting the string into an array. use the reverse() method.

3. .join('') the array back into a string and return it out of the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment