🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of freddie2025

freddie2025's solution

to Reverse String in the JavaScript Track

Published at Mar 25 2020 · 0 comments
Test suite

Reverse a string

For example: input: "cool" output: "looc"


Go through the setup instructions for Javascript to install the necessary dependencies:



Install assignment dependencies:

$ npm install

Making the test suite pass

Execute the tests with:

$ npm test

In the test suites all tests but the first have been skipped.

Once you get a test passing, you can enable the next one by changing xtest to test.


Introductory challenge to reverse an input string https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


import { reverseString } from './reverse-string';

describe('ReverseString', () => {
  test('empty string', () => {
    const expected = '';
    const actual = reverseString('');

  xtest('a word', () => {
    const expected = 'tobor';
    const actual = reverseString('robot');

  xtest('a capitalized word', () => {
    const expected = 'nemaR';
    const actual = reverseString('Ramen');

  xtest('a sentence with punctuation', () => {
    const expected = '!yrgnuh ma I';
    const actual = reverseString('I am hungry!');

  xtest('a palindrome', () => {
    const expected = 'racecar';
    const actual = reverseString('racecar');

  xtest('an even-sized word', () => {
    const expected = 'reward';
    const actual = reverseString('drawer');
// This is only a SKELETON file for the 'Reverse String' exercise. It's been provided as a
// convenience to get you started writing code faster.

export const reverseString = (input) => {
  return input.split("").reverse().join("");

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?