Problem Solving | Reverse a string

Problem Solving | Reverse a string

Chirag Ramachandra's photo
Chirag Ramachandra
·Jan 10, 2021·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Given a string, return a new string with the reversed order of characters.


reverse('apple') === 'leppa'

reverse('hello') === 'olleh'

reverse('Greetings!') === '!sgniteerG'

Pseudo Solution:

  1. Convert the string to array
  2. Reverse the array using javascript reverse function
  3. Join the array back to string using .join function
  4. Return the string
function reverse(str) {

let arrayString = [... str]
return arrayString.join('');


Simplified solution:

function reverse(str) {
  return [...str].reverse().join('');

Without using the .reverse function

function reverse(str) {
  let reversed = "";

  for (let character of str) {
    reversed = character + reversed;

  return reversed;

Share this