Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

reverse string exercise #417

Merged
merged 19 commits into from
Dec 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
],
"uuid": "0c231a1c-55f7-47b6-8a54-ccae4ab0c65b"
},
{
"core": false,
"difficulty": 2,
"slug": "reverse-string",
"topics": [
"loops",
"for",
"strings"
],
"unlocked_by": "leap",
"uuid": "553a6be7-eecb-45dc-9cea-05126c525f1b"
},
{
"core": true,
"difficulty": 1,
Expand Down
36 changes: 36 additions & 0 deletions exercises/reverse-string/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Reverse String

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


## Setup

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

http://exercism.io/languages/javascript

## Making the Test Suite Pass

Execute the tests with:

jasmine <exercise-name>.spec.js

Replace `<exercise-name>` with the name of the current exercise. E.g., to
test the Reverse String exercise:

jasmine reverse-string.spec.js

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

Once you get a test passing, you can unskip the next one by
changing `xit` to `it`.

## Source

This is an exercise to introduce users to using Exercism and arrays and strings [https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb](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.
11 changes: 11 additions & 0 deletions exercises/reverse-string/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

function reverseString(string) {
var revString = '';
for (var i = string.length - 1; i >= 0; i--) {
revString += string[i];
}
return revString;
}

module.exports = reverseString;
33 changes: 33 additions & 0 deletions exercises/reverse-string/reverse-string.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var reverseString = require('./reverse-string');

describe('ReverseString', function () {
it('empty string', function () {
var expected = '';
var actual = reverseString('');
expect(actual).toEqual(expected);
});

xit('a word', function () {
var expected = 'tobor';
var actual = reverseString('robot');
expect(actual).toEqual(expected);
});

xit('a capitalized word', function () {
var expected = 'nemaR';
var actual = reverseString('Ramen');
expect(actual).toEqual(expected);
});

xit('a sentence with punctuation', function () {
var expected = '!yrgnuh ma I';
var actual = reverseString('I am hungry!');
expect(actual).toEqual(expected);
});

xit('a palindrome', function () {
var expected = 'racecar';
var actual = reverseString('racecar');
expect(actual).toEqual(expected);
});
});