Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 1.14 KB

File metadata and controls

38 lines (26 loc) · 1.14 KB

Reverse a String

Problem

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. Write your own code.

Here are some helpful links:

Solution

function reverseString(str) {
  var arr = str.split("");
  arr = arr.reverse();
  str = arr.join("");
  return str;
}

reverseString("hello");

Tests

  • reverseString("hello") should return a string.
  • reverseString("hello") should become "olleh".
  • reverseString("Howdy") should become "ydwoH".
  • reverseString("Greetings from Earth") should return "htraE morf sgniteerG".