-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem:
Reverse a String
Examples:
reverseString(“hello”) should become “olleh”
reverseString(“world”) should become “dlrow”
reverseString(“wizard”) should return ”draziw”
Difficulty:
Easy
Language:
Javascript
Steps to Solve:
Step 1. Use the split() method to return a new array
Step 2. Use the reverse() method to reverse the new created array
Step 3. Use the join() method to join all elements of the array into a string
Code Solution:
function reverseString(str) {
var splitString = str.split("");
var reverseArray = splitString.reverse();
var joinArray = reverseArray.join("");
return joinArray;
}
OPTIONAL Notes:
Assumes we can use built-in javascript functions
OPTIONAL Storyboard Notes:
Could use this problem for a Mirror of Erised scene. (The task: read "Erised" backwards)
OPTIONAL Source:
https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb