Bonfire Reverse a String - GJSmith3rd/FreeCodeCamp-BootCamp GitHub Wiki

Contact me

Gilbert Joseph Smith III

@gjsmith3rd

Github | FreeCodeCamp | CodePen | LinkedIn | Blog/Site | E-Mail

Details

  • Difficulty: 1/5

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.

Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.

Useful Links

Problem Script:

function reverseString(str) {
  return str;
}

reverseString('hello');

Explanation:

You need to take the string and reverse it so if you had originally 'hello', it will turn into 'olleh'. Because you will need to split it, you will be working with Arrays too.

Hint: 1

You should split the string by characters.

Hint: 2

Find out about the built in function to reverse a string.

Hint: 3

Once you have split and reversed, do not forget to join them back into one string.

My code:

function reverseString(str) {
  var strReverse = str.split('').reverse().join('');
  return strReverse;
}

My Code Explanation:

This is a straightforward code. We create a variable that will hold the string split by characters, and then reversed and put back together.