diff --git a/exercises/reverse-string/README.md b/exercises/reverse-string/README.md new file mode 100644 index 00000000..7b046b5b --- /dev/null +++ b/exercises/reverse-string/README.md @@ -0,0 +1,106 @@ +# Reverse String + +The introductory exercise to arrays and strings. Just reverse input string. + +This is a typical first program for beginning programming in a new language +or environment after being able to do simple tasks. + +The objectives are simple: + +- Write a function that reverses the input string. +- Run the test suite and make sure that it succeeds. +- Submit your solution and check it at the website. + +If everything goes well, you will be ready to fetch your first real exercise. + +## Tutorial + +This exercise has two files: + +- reverse-string.js +- reverse-string.spec.js + +The first file is where you will write your code. +The second is where the tests are defined. + +The tests will check whether your code is doing the right thing. +You don't need to be able to write a test suite from scratch, +but it helps to understand what a test looks like, and what +it is doing. + +Open up the test file, reverse-string.spec.js. +There is one test inside: + + xit('detects simple reverse string', function () { + var subject = new ReverseString('ant'); + var matches = subject.matches(['tna']); + + expect(matches).toEqual(['tna']); + }); + +Run the test now, with the following command on the command-line: + + jasmine reverse-string.spec.js + +The test fails, which makes sense since you've not written any code yet. + +The failure looks like this: + + 1) Reverse String says reverse string + Message: + Expected undefined to equal 'tna'. + +There's more, but this is the most important part. + +Take a look at that first line: + + 1) Reverse String says reverse string + +Now look at the test definition again: + + it('detects simple reverse string', function() { + // ... more code here ... + }); + +Update the code and then run the tests again from the command-line: + + jasmine reverse-string.spec.js + +Notice how it changes the failure message. + +Then change the implementation in reverse-string.js again, this time to make the test pass. + +When you are done, submit your solution to exercism: + + exercism submit reverse-string.js + + +## 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 .spec.js + +Replace `` 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. diff --git a/exercises/reverse-string/canonical-schema.json b/exercises/reverse-string/canonical-schema.json new file mode 100644 index 00000000..33cc26ec --- /dev/null +++ b/exercises/reverse-string/canonical-schema.json @@ -0,0 +1,54 @@ +{ + "exercise": "revere-string", + "version": "1.0.1", + "comments": [ + "The string argument cases possible matches are passed in as", + "individual arguments rather than arrays. Languages can include", + "these string argument cases if passing individual arguments is", + "idiomatic in that language." + ], + "cases": [ + { + "description": "no matches", + "property": "reverse-string", + "subject": "car", + "candidates": ["girl", "Japan", "bear", "candy"], + "expected": [] + }, + { + "description": "detects simple reverse string", + "property": "reverse-string", + "subject": "ant", + "candidates": ["tna"], + "expected": ["tan"] + }, + { + "description": "detects reverse-string", + "property": "reverse-string", + "subject": "listen", + "candidates": ["netsil"], + "expected": ["netsil"] + }, + { + "description": "detects anagrams case-insensitively", + "property": "reverse-string", + "subject": "NinJa", + "candidates": ["ajnin"], + "expected": ["ajnin"] + }, + { + "description": "matches() accepts string arguments", + "property": "reverse-string", + "subject": "ant", + "candidates": ["tna"], + "expected": ["tna"] + }, + { + "description": "matches() accepts single string argument", + "property": "reverse-string", + "subject": "ant", + "candidates": ["ant"], + "expected": ["tna"] + } + ] +} \ No newline at end of file diff --git a/exercises/reverse-string/example.js b/exercises/reverse-string/example.js new file mode 100644 index 00000000..2b9180d6 --- /dev/null +++ b/exercises/reverse-string/example.js @@ -0,0 +1,14 @@ +'use strict'; + +function reverseString(s) {} + +ReverseString.prototype.convert = function (s) { + + var rString = ''; + for (var i=s.length-1; i>=0; i--){ + rString += s[i]; + } + return rString; +}; + +module.exports = ReverseString; diff --git a/exercises/reverse-string/reverse-string.js b/exercises/reverse-string/reverse-string.js new file mode 100644 index 00000000..f161a16d --- /dev/null +++ b/exercises/reverse-string/reverse-string.js @@ -0,0 +1,15 @@ +// +// This is a stub file for the 'Reverse String' exercise. It's been provided as a +// convenience to get you started writing code faster. +// Make sure to look at reverse-string.spec.js--that should give you some hints about what is +// expected here. + +var ReverseString = function () {}; + +ReverseString.prototype.reverse = function () { +// +// YOUR CODE GOES HERE +// +}; + +module.exports = ReverseString; diff --git a/exercises/reverse-string/reverse-string.spec.js b/exercises/reverse-string/reverse-string.spec.js new file mode 100644 index 00000000..e6cfbbf2 --- /dev/null +++ b/exercises/reverse-string/reverse-string.spec.js @@ -0,0 +1,51 @@ +var ReverseString = require('./reverse-string'); + +describe('ReverseString', function () { + it('no matches', function () { + var subject = new ReverseString('car'); + var matches = subject.matches([ 'girl', 'Japan', 'bear', 'candy']); + + expect(matches).toEqual([]); + }); + + xit('detects simple reverse string', function () { + var subject = new ReverseString('ant'); + var matches = subject.matches(['tna']); + + expect(matches).toEqual(['tna']); + }); + + + + xit('detects anagram', function () { + var subject = new ReverseString('listen'); + var matches = subject.matches(['netsil']); + + expect(matches).toEqual(['netsil']); + }); + + + + xit('detects anagrams case-insensitively', function () { + var subject = new ReverseString('NinJa'); + var matches = subject.matches(['ajnin']); + + expect(matches).toEqual(['ajnin']); + }); + + + + xit('matches() accepts string arguments', function () { + var subject = new ReverseString('ant'); + var matches = subject.matches('tna'); + + expect(matches).toEqual(['tna']); + }); + + xit('matches() accepts single string argument', function () { + var subject = new ReverseString('ant'); + var matches = subject.matches('tna'); + + expect(matches).toEqual(['tna']); + }); +}); \ No newline at end of file