Skip to content

Problem: Reverse a String #1

@lpatmo

Description

@lpatmo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions