String reversal

JavaScript
Easy

Objective

Write a function that reverses a string

Requirements

  1. The function should be named reverseString

  2. It should take a single string as an argument

  3. It should return the reversed string

Check your solution

Tests

Function name is reverseString
reverseString("lorem")Expected:"merol"
reverseString("a b c")Expected:"c b a"

Solution

Here's how I would approach this, but keep in mind there might be other ways to solve this problem.

function reverseString(string) { // Turn the string into an array, reverse it, then turn it back into a string return string.split('').reverse().join(''); }
Click to reveal