diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..03223202 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +big-integer.js +exercises/grains/big-integer.js +exercises/grains/big-integer.spec.js diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 50b380a4..00000000 --- a/.eslintrc.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "plugins": ["jasmine"], - "extends": "eslint-config-airbnb-es5", - "env": { - "jasmine": true - }, - "rules": { - "func-names": "off" - } -} diff --git a/.travis.yml b/.travis.yml index 9dce3c35..45fde31c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,12 +3,13 @@ language: node_js sudo: false node_js: - - "node" + - "lts/*" install: - - "npm install -g jasmine" + - "npm install" script: - "make test" - "./bin/fetch-configlet" - "./bin/configlet lint ." + - "npm run lint" diff --git a/README.md b/README.md index e6c52fb4..4f5bffa2 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,3 @@ -# JavaScript [![Build Status](https://travis-ci.org/exercism/javascript.svg?branch=master)](https://travis-ci.org/exercism/javascript) - -Exercism exercises in JavaScript - -## Installing - -To run the tests, you'll need NodeJS and Jasmine. For information about how to install these tools, see the [Javascript](http://exercism.io/languages/javascript/about) page. - -## Tasks - -The following commands assume that you are in the `javascript` directory: - -### Unit Tests: All Assignments - - make test - -### Unit Tests: Single Assignment - - make test-assignment ASSIGNMENT=wordy - -### Code Style - - npm run lint - -## Contributing Guide - -Please see the [contributing guide](https://github.com/exercism/x-api/blob/master/CONTRIBUTING.md#the-exercise-data) +# DEPRECATION NOTICE +This track is deprecated. Please see the https://github.com/exercism/javascript track. diff --git a/config.json b/config.json index 73522338..e11dd1f6 100644 --- a/config.json +++ b/config.json @@ -1,1132 +1,1221 @@ { - "active": true, + "language": "JavaScript (Legacy)", + "active": false, + "blurb": "JavaScript is a scripting language, primarily used for creating dynamic websites and programming web servers. It's a very popular language, and supports a variety of programming paradigms.", + "test_pattern": ".*[.]spec[.]js$", "exercises": [ { + "slug": "hello-world", + "uuid": "4756cfc9-7509-4783-8be7-60e3376b8256", "core": true, + "unlocked_by": null, "difficulty": 1, - "slug": "hello-world", "topics": [ - "control-flow-(conditionals)", - "optional-values", + "control_flow_conditionals", + "optional_values", "strings", - "text-formatting" - ], - "uuid": "4756cfc9-7509-4783-8be7-60e3376b8256" + "text_formatting" + ] }, { - "core": true, + "slug": "two-fer", + "uuid": "5f3d1326-f0c5-44a6-b90a-6af3b7d455f1", + "core": false, + "unlocked_by": "hello-world", "difficulty": 1, + "topics": [ + "control_flow_conditionals", + "strings" + ] + }, + { "slug": "leap", + "uuid": "0c231a1c-55f7-47b6-8a54-ccae4ab0c65b", + "core": true, + "unlocked_by": null, + "difficulty": 1, "topics": [ "booleans", "integers", "logic" - ], - "uuid": "0c231a1c-55f7-47b6-8a54-ccae4ab0c65b" + ] }, { + "slug": "reverse-string", + "uuid": "553a6be7-eecb-45dc-9cea-05126c525f1b", + "core": false, + "unlocked_by": "leap", + "difficulty": 2, + "topics": [ + "for", + "loops", + "strings" + ] + }, + { + "slug": "rna-transcription", + "uuid": "d7f57ab9-2edb-44cb-a04e-c575c0f4be4c", "core": true, + "unlocked_by": null, "difficulty": 1, - "slug": "rna-transcription", "topics": [ "strings", "transforming" - ], - "uuid": "d7f57ab9-2edb-44cb-a04e-c575c0f4be4c" + ] }, { + "slug": "simple-cipher", + "uuid": "fff57c49-cde9-4a0c-b70b-2903cef212af", "core": true, + "unlocked_by": null, "difficulty": 1, - "slug": "simple-cipher", "topics": [ "algorithms", - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "mathematics", "randomness", "strings", - "text-formatting", + "text_formatting", "transforming" - ], - "uuid": "fff57c49-cde9-4a0c-b70b-2903cef212af" + ] }, { + "slug": "pangram", + "uuid": "c57bf909-130f-46e6-97ca-aeed58df1a15", "core": true, + "unlocked_by": null, "difficulty": 2, - "slug": "pangram", "topics": [ "algorithms", - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "lists", "maps", "searching", "strings" - ], - "uuid": "c57bf909-130f-46e6-97ca-aeed58df1a15" + ] }, { + "slug": "bob", + "uuid": "246be5d9-b361-4893-9707-f218ede2bed6", "core": true, + "unlocked_by": null, "difficulty": 2, - "slug": "bob", "topics": [ - "control-flow-(conditionals)", - "pattern-recognition", + "control_flow_conditionals", + "pattern_recognition", "polymorfism", - "regular-expressions", + "regular_expressions", "strings", "unicode" - ], - "uuid": "246be5d9-b361-4893-9707-f218ede2bed6" + ] }, { + "slug": "gigasecond", + "uuid": "49e4874b-d7e2-4305-a9bc-627fab4ada44", "core": true, + "unlocked_by": null, "difficulty": 2, - "slug": "gigasecond", "topics": [ "time" - ], - "uuid": "49e4874b-d7e2-4305-a9bc-627fab4ada44" + ] }, { + "slug": "space-age", + "uuid": "b668e11a-a8ce-4e94-ba68-3a1f0fa3f6c8", "core": true, + "unlocked_by": null, "difficulty": 3, - "slug": "space-age", "topics": [ "classes", - "floating-point-numbers", + "floating_point_numbers", "mathematics" - ], - "uuid": "b668e11a-a8ce-4e94-ba68-3a1f0fa3f6c8" + ] }, { + "slug": "binary", + "uuid": "c3035180-ff4c-4afe-8019-f8364158b74e", "core": true, + "unlocked_by": null, "difficulty": 4, - "slug": "binary", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling", "integers", "mathematics", - "regular-expressions", + "regular_expressions", "strings" - ], - "uuid": "c3035180-ff4c-4afe-8019-f8364158b74e" + ] }, { + "slug": "prime-factors", + "uuid": "73ecd6c2-e59b-4354-b305-64e28a60433f", "core": true, + "unlocked_by": null, "difficulty": 4, - "slug": "prime-factors", "topics": [ "algorithms", - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "integers", "mathematics" - ], - "uuid": "73ecd6c2-e59b-4354-b305-64e28a60433f" + ] }, { + "slug": "matrix", + "uuid": "fbfe6032-c209-40bd-b485-8b2881638166", "core": true, + "unlocked_by": null, "difficulty": 4, - "slug": "matrix", "topics": [ "arrays", - "control-flow-(conditionals)", - "control-flow-(loops)", - "data-structures", + "control_flow_conditionals", + "control_flow_loops", + "data_structures", "matrices", - "text-formatting" - ], - "uuid": "fbfe6032-c209-40bd-b485-8b2881638166" + "text_formatting" + ] }, { + "slug": "linked-list", + "uuid": "ecc41237-f629-458f-873e-2cc51ba1a385", "core": true, + "unlocked_by": null, "difficulty": 5, - "slug": "linked-list", "topics": [ "algorithms", "arrays", - "control-flow-(conditionals)", - "control-flow-(loops)", - "data-structures", + "control_flow_conditionals", + "control_flow_loops", + "data_structures", "lists", - "optional-values" - ], - "uuid": "ecc41237-f629-458f-873e-2cc51ba1a385" + "optional_values" + ] }, { + "slug": "pascals-triangle", + "uuid": "a96ab45d-10a0-42cf-a754-c2466037ceaf", "core": true, + "unlocked_by": null, "difficulty": 5, - "slug": "pascals-triangle", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "mathematics", "strings", - "text-formatting" - ], - "uuid": "a96ab45d-10a0-42cf-a754-c2466037ceaf" + "text_formatting" + ] }, { + "slug": "secret-handshake", + "uuid": "0a3a452c-f734-47eb-8e65-34c8ae710ef0", "core": true, + "unlocked_by": null, "difficulty": 6, - "slug": "secret-handshake", "topics": [ "algorithms", "arrays", - "bitwise-operations", - "control-flow-(conditionals)", - "control-flow-(loops)", + "bitwise_operations", + "control_flow_conditionals", + "control_flow_loops", "games" - ], - "uuid": "0a3a452c-f734-47eb-8e65-34c8ae710ef0" + ] }, { - "core": true, + "slug": "rotational-cipher", + "uuid": "7078b1a4-ef73-4c02-809d-b2de62e9af11", + "core": false, + "unlocked_by": "secret-handshake", "difficulty": 6, + "topics": [ + "cryptography", + "integers", + "strings" + ] + }, + { "slug": "grade-school", + "uuid": "029bc3ed-772d-439b-bd0a-1ba1196a79ec", + "core": true, + "unlocked_by": null, + "difficulty": 6, "topics": [ "arrays", "maps", "sorting" - ], - "uuid": "029bc3ed-772d-439b-bd0a-1ba1196a79ec" + ] }, { + "slug": "robot-name", + "uuid": "3005340b-a8d6-46ac-9075-125f9adccc2a", "core": true, + "unlocked_by": null, "difficulty": 6, - "slug": "robot-name", "topics": [ - "control-flow-(conditionals)", - "exception-handling", + "control_flow_conditionals", + "exception_handling", "randomness", - "regular-expressions", + "regular_expressions", "sets" - ], - "uuid": "3005340b-a8d6-46ac-9075-125f9adccc2a" + ] }, { + "slug": "wordy", + "uuid": "bb54bf08-24ba-45e1-bdf7-08db161e5843", "core": true, + "unlocked_by": null, "difficulty": 7, - "slug": "wordy", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling", "parsing", - "pattern-recognition", - "regular-expressions", + "pattern_recognition", + "regular_expressions", "strings" - ], - "uuid": "bb54bf08-24ba-45e1-bdf7-08db161e5843" + ] }, { + "slug": "list-ops", + "uuid": "e70defe4-5944-4392-956c-63cb92e7fd9c", "core": true, + "unlocked_by": null, "difficulty": 8, - "slug": "list-ops", "topics": [ - "data-structures", + "data_structures", "lists", "recursion" - ], - "uuid": "e70defe4-5944-4392-956c-63cb92e7fd9c" + ] }, { + "slug": "rational-numbers", + "uuid": "2de5677e-5759-4a21-93c7-39a3d88242e8", "core": false, - "difficulty": 2, + "unlocked_by": "pascals-triangle", + "difficulty": 5, + "topics": [ + "algorithms", + "floating_point_numbers", + "mathematics" + ] + }, + { "slug": "hamming", + "uuid": "3e1358c8-2bea-41f9-bc9e-8277f354a4e0", + "core": false, + "unlocked_by": "rna-transcription", + "difficulty": 2, "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "equality", "strings" - ], - "unlocked_by": "rna-transcription", - "uuid": "3e1358c8-2bea-41f9-bc9e-8277f354a4e0" + ] }, { + "slug": "run-length-encoding", + "uuid": "d66c2b56-b465-4922-af35-ae78944c0aac", "core": false, + "unlocked_by": null, "difficulty": 2, - "slug": "run-length-encoding", "topics": [ - "control-flow-(conditionals)", - "exception-handling", + "control_flow_conditionals", + "exception_handling", "parsing", - "pattern-recognition", - "regular-expressions", + "pattern_recognition", + "regular_expressions", "strings", - "text-formatting" - ], - "unlocked_by": null, - "uuid": "d66c2b56-b465-4922-af35-ae78944c0aac" + "text_formatting" + ] }, { + "slug": "isogram", + "uuid": "35821375-5c94-4d4b-aa56-e3b079a45ca0", "core": false, + "unlocked_by": "pangram", "difficulty": 2, - "slug": "isogram", "topics": [ "filtering", "strings" - ], - "unlocked_by": "pangram", - "uuid": "35821375-5c94-4d4b-aa56-e3b079a45ca0" + ] }, { + "slug": "beer-song", + "uuid": "6f315fc3-095a-4387-aefb-cc5fee97110a", "core": false, + "unlocked_by": "bob", "difficulty": 5, - "slug": "beer-song", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "strings" - ], - "unlocked_by": "bob", - "uuid": "6f315fc3-095a-4387-aefb-cc5fee97110a" + ] }, { + "slug": "phone-number", + "uuid": "347f9f54-a0d9-469d-babf-b3edb34d9d70", "core": false, + "unlocked_by": "pangram", "difficulty": 3, - "slug": "phone-number", "topics": [ "parsing", "transforming" - ], - "unlocked_by": "pangram", - "uuid": "347f9f54-a0d9-469d-babf-b3edb34d9d70" + ] }, { + "slug": "anagram", + "uuid": "432ec2ce-c919-4142-aea2-389b67503252", "core": false, + "unlocked_by": "pangram", "difficulty": 1, - "slug": "anagram", "topics": [ "filtering", "strings" - ], - "unlocked_by": "pangram", - "uuid": "432ec2ce-c919-4142-aea2-389b67503252" + ] }, { + "slug": "food-chain", + "uuid": "a717745f-da00-4a5f-8bf3-6876e20cdf17", "core": false, + "unlocked_by": "bob", "difficulty": 4, - "slug": "food-chain", "topics": [ "algorithms", - "text-formatting" - ], - "unlocked_by": "bob", - "uuid": "a717745f-da00-4a5f-8bf3-6876e20cdf17" + "text_formatting" + ] }, { + "slug": "etl", + "uuid": "a2a19f61-62ba-447a-8f57-537c8baa2e7a", "core": false, + "unlocked_by": "rna-transcription", "difficulty": 2, - "slug": "etl", "topics": [ - "control-flow-(loops)", + "control_flow_loops", "integers", "maps", "transforming" - ], - "unlocked_by": "rna-transcription", - "uuid": "a2a19f61-62ba-447a-8f57-537c8baa2e7a" + ] }, { + "slug": "sublist", + "uuid": "4a83a72c-db0a-45b6-b77c-1949cb24fbae", "core": false, + "unlocked_by": "linked-list", "difficulty": 4, - "slug": "sublist", "topics": [ "arrays", "lists" - ], - "unlocked_by": "linked-list", - "uuid": "4a83a72c-db0a-45b6-b77c-1949cb24fbae" + ] }, { + "slug": "grains", + "uuid": "c5be6908-f45c-4278-ba99-3701024f4eda", "core": false, + "unlocked_by": "space-age", "difficulty": 5, - "slug": "grains", "topics": [ - "control-flow-(loops)", + "control_flow_loops", "integers", "mathematics" - ], - "unlocked_by": "space-age", - "uuid": "c5be6908-f45c-4278-ba99-3701024f4eda" + ] }, { + "slug": "triangle", + "uuid": "fde792fa-84e9-4b86-8ecb-8466ad92a99d", "core": false, + "unlocked_by": "leap", "difficulty": 3, - "slug": "triangle", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling", "integers", "mathematics" - ], - "unlocked_by": "leap", - "uuid": "fde792fa-84e9-4b86-8ecb-8466ad92a99d" + ] }, { + "slug": "clock", + "uuid": "1ff85150-6c51-4758-af02-4484cf35658e", "core": false, + "unlocked_by": "gigasecond", "difficulty": 5, - "slug": "clock", "topics": [ "dates", "globalization", "time" - ], - "unlocked_by": "gigasecond", - "uuid": "1ff85150-6c51-4758-af02-4484cf35658e" + ] }, { + "slug": "perfect-numbers", + "uuid": "51aa5429-b2db-43ad-83cf-84e2ead22cb6", "core": false, + "unlocked_by": "space-age", "difficulty": 3, - "slug": "perfect-numbers", "topics": [ "arrays", - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "integers", "mathematics" - ], - "unlocked_by": "space-age", - "uuid": "51aa5429-b2db-43ad-83cf-84e2ead22cb6" + ] }, { + "slug": "word-count", + "uuid": "9a4ea3da-ad43-4850-bdf3-2c578c5de838", "core": false, + "unlocked_by": "pangram", "difficulty": 1, - "slug": "word-count", "topics": [ - "control-flow-(loops)", + "control_flow_loops", "lists", - "regular-expressions", + "regular_expressions", "strings", "unicode" - ], - "unlocked_by": "pangram", - "uuid": "9a4ea3da-ad43-4850-bdf3-2c578c5de838" + ] }, { + "slug": "acronym", + "uuid": "0c1c4788-0372-42e7-81c1-b090bb7ebc8b", "core": false, + "unlocked_by": "pangram", "difficulty": 2, - "slug": "acronym", "topics": [ - "control-flow-(loops)", - "regular-expressions", + "control_flow_loops", + "regular_expressions", "strings", "transforming" - ], - "unlocked_by": "pangram", - "uuid": "0c1c4788-0372-42e7-81c1-b090bb7ebc8b" + ] }, { + "slug": "scrabble-score", + "uuid": "a6bd8126-3879-4593-8380-39ebfa87801b", "core": false, + "unlocked_by": "rna-transcription", "difficulty": 5, - "slug": "scrabble-score", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "maps", "strings" - ], - "unlocked_by": "rna-transcription", - "uuid": "a6bd8126-3879-4593-8380-39ebfa87801b" + ] }, { + "slug": "roman-numerals", + "uuid": "4226e3c6-99d4-406d-998a-bcf11845b211", "core": false, + "unlocked_by": null, "difficulty": 3, - "slug": "roman-numerals", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "mathematics", - "pattern-recognition", + "pattern_recognition", "transforming" - ], - "unlocked_by": null, - "uuid": "4226e3c6-99d4-406d-998a-bcf11845b211" + ] }, { + "slug": "circular-buffer", + "uuid": "f1943e87-182a-44f5-a885-3d68a0c0a0dc", "core": false, + "unlocked_by": "linked-list", "difficulty": 8, - "slug": "circular-buffer", "topics": [ "arrays", - "control-flow-(conditionals)", - "control-flow-(loops)", - "data-structures", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "data_structures", + "exception_handling", "lists" - ], - "unlocked_by": "linked-list", - "uuid": "f1943e87-182a-44f5-a885-3d68a0c0a0dc" + ] }, { + "slug": "raindrops", + "uuid": "86b1acf1-9e2d-4b04-b8b0-e9ae6beb5f3d", "core": false, + "unlocked_by": "rna-transcription", "difficulty": 2, - "slug": "raindrops", "topics": [ - "control-flow-(conditionals)", + "control_flow_conditionals", "integers", "strings", "transforming" - ], - "unlocked_by": "rna-transcription", - "uuid": "86b1acf1-9e2d-4b04-b8b0-e9ae6beb5f3d" + ] }, { + "slug": "allergies", + "uuid": "23210e9e-81f6-4279-a776-00459c7ccd02", "core": false, + "unlocked_by": "rna-transcription", "difficulty": 6, - "slug": "allergies", "topics": [ "arrays", - "bitwise-operations", - "control-flow-(conditionals)", - "control-flow-(loops)" - ], - "unlocked_by": "rna-transcription", - "uuid": "23210e9e-81f6-4279-a776-00459c7ccd02" + "bitwise_operations", + "control_flow_conditionals", + "control_flow_loops" + ] }, { + "slug": "strain", + "uuid": "e61f3d54-55d2-4d32-9d2a-e7d6af3a3247", "core": false, + "unlocked_by": "list-ops", "difficulty": 4, - "slug": "strain", "topics": [ "algorithms", "arrays", "callbacks", - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "filtering", "lists" - ], - "unlocked_by": "list-ops", - "uuid": "e61f3d54-55d2-4d32-9d2a-e7d6af3a3247" + ] }, { + "slug": "atbash-cipher", + "uuid": "99974454-0736-4cc0-b88f-ed5701397a97", "core": false, + "unlocked_by": "simple-cipher", "difficulty": 7, - "slug": "atbash-cipher", "topics": [ "algorithms", "arrays", - "control-flow-(conditionals)", - "control-flow-(loops)", - "regular-expressions", - "text-formatting" - ], - "unlocked_by": "simple-cipher", - "uuid": "99974454-0736-4cc0-b88f-ed5701397a97" + "control_flow_conditionals", + "control_flow_loops", + "regular_expressions", + "text_formatting" + ] }, { + "slug": "accumulate", + "uuid": "dc9b2598-9757-4b20-82f9-8049ad081ac9", "core": false, + "unlocked_by": "list-ops", "difficulty": 5, - "slug": "accumulate", "topics": [ "algorithms", "callbacks", - "control-flow-(loops)", + "control_flow_loops", "lists" - ], - "unlocked_by": "list-ops", - "uuid": "dc9b2598-9757-4b20-82f9-8049ad081ac9" + ] }, { + "slug": "crypto-square", + "uuid": "a98e3593-d5b4-4c2b-8569-ae3ae7e07dad", "core": false, + "unlocked_by": "simple-cipher", "difficulty": 9, - "slug": "crypto-square", "topics": [ "algorithms", "arrays", - "control-flow-(conditionals)", - "control-flow-(loops)", - "regular-expressions", + "control_flow_conditionals", + "control_flow_loops", + "regular_expressions", "sorting", - "text-formatting", + "text_formatting", "transforming" - ], - "unlocked_by": "atbash-cipher", - "uuid": "a98e3593-d5b4-4c2b-8569-ae3ae7e07dad" + ] }, { + "slug": "trinary", + "uuid": "f317721d-e1f5-4e68-9fdc-f9bc7b6b004d", "core": false, + "unlocked_by": "binary", "difficulty": 4, - "slug": "trinary", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "integers", "mathematics", - "regular-expressions", + "regular_expressions", "strings" - ], - "unlocked_by": "binary", - "uuid": "f317721d-e1f5-4e68-9fdc-f9bc7b6b004d" + ] }, { + "slug": "sieve", + "uuid": "4cad8ee8-40be-4d4d-8c14-45d8c6e29a32", "core": false, + "unlocked_by": "prime-factors", "difficulty": 5, - "slug": "sieve", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "integers", "mathematics", "recursion" - ], - "unlocked_by": "prime-factors", - "uuid": "4cad8ee8-40be-4d4d-8c14-45d8c6e29a32" + ] }, { + "slug": "octal", + "uuid": "9892d47d-97a0-4a2f-8284-6f84c86559e8", "core": false, + "unlocked_by": "binary", "difficulty": 4, - "slug": "octal", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "integers", "mathematics", - "regular-expressions", + "regular_expressions", "strings" - ], - "unlocked_by": "binary", - "uuid": "9892d47d-97a0-4a2f-8284-6f84c86559e8" + ] }, { + "slug": "luhn", + "uuid": "bb46e832-8c37-45ee-9ee7-5037015b965c", "core": false, + "unlocked_by": "space-age", "difficulty": 4, - "slug": "luhn", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "integers", "mathematics", "strings" - ], - "unlocked_by": "space-age", - "uuid": "bb46e832-8c37-45ee-9ee7-5037015b965c" + ] }, { + "slug": "pig-latin", + "uuid": "9a515ad0-34c7-4191-8784-5c4cd6385b38", "core": false, + "unlocked_by": "bob", "difficulty": 4, - "slug": "pig-latin", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "games", - "regular-expressions", + "regular_expressions", "strings", "transforming" - ], - "unlocked_by": "bob", - "uuid": "9a515ad0-34c7-4191-8784-5c4cd6385b38" + ] }, { + "slug": "pythagorean-triplet", + "uuid": "26a973dd-d72e-40fb-abeb-0ba306356ed6", "core": false, + "unlocked_by": "space-age", "difficulty": 5, - "slug": "pythagorean-triplet", "topics": [ "algorithms", - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "integers", "mathematics" - ], - "unlocked_by": "space-age", - "uuid": "26a973dd-d72e-40fb-abeb-0ba306356ed6" + ] }, { + "slug": "series", + "uuid": "06afdb06-8d2a-4cb0-baf1-48ae997cf1f5", "core": false, + "unlocked_by": "pangram", "difficulty": 3, - "slug": "series", "topics": [ - "control-flow-(loops)", - "exception-handling", + "control_flow_loops", + "exception_handling", "strings", - "text-formatting" - ], - "unlocked_by": "pangram", - "uuid": "06afdb06-8d2a-4cb0-baf1-48ae997cf1f5" + "text_formatting" + ] }, { + "slug": "difference-of-squares", + "uuid": "07110dd5-b879-40b9-9485-685cb0963d8f", "core": false, + "unlocked_by": "space-age", "difficulty": 3, - "slug": "difference-of-squares", "topics": [ "algorithms", - "control-flow-(loops)", + "control_flow_loops", "integers", "mathematics" - ], - "unlocked_by": "space-age", - "uuid": "07110dd5-b879-40b9-9485-685cb0963d8f" + ] }, { + "slug": "proverb", + "uuid": "8786d591-077b-49bc-be8d-d014dc9dc308", "core": false, + "unlocked_by": "bob", "difficulty": 4, - "slug": "proverb", "topics": [ "arrays", - "control-flow-(conditionals)", - "control-flow-(loops)", - "optional-values", + "control_flow_conditionals", + "control_flow_loops", + "optional_values", "strings", - "text-formatting" - ], - "unlocked_by": "bob", - "uuid": "8786d591-077b-49bc-be8d-d014dc9dc308" + "text_formatting" + ] }, { + "slug": "flatten-array", + "uuid": "32a0a5fa-c7de-470c-beff-118b448b3916", "core": false, + "unlocked_by": "list-ops", "difficulty": 1, - "slug": "flatten-array", "topics": [ "arrays", "recursion" - ], - "unlocked_by": "list-ops", - "uuid": "32a0a5fa-c7de-470c-beff-118b448b3916" + ] }, { + "slug": "hexadecimal", + "uuid": "33b8f4c0-3210-478a-9225-5c30ad6df870", "core": false, + "unlocked_by": "binary", "difficulty": 4, - "slug": "hexadecimal", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "integers", "mathematics", - "regular-expressions", + "regular_expressions", "strings" - ], - "unlocked_by": "binary", - "uuid": "33b8f4c0-3210-478a-9225-5c30ad6df870" + ] }, { + "slug": "largest-series-product", + "uuid": "44bd02a7-0e3a-4441-ab76-524e36d4661c", "core": false, + "unlocked_by": "pangram", "difficulty": 7, - "slug": "largest-series-product", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling", "integers", "mathematics", - "regular-expressions", + "regular_expressions", "strings" - ], - "unlocked_by": "pangram", - "uuid": "44bd02a7-0e3a-4441-ab76-524e36d4661c" + ] }, { + "slug": "kindergarten-garden", + "uuid": "2702ac90-0be2-43a2-91b6-7256a25fec87", "core": false, + "unlocked_by": "wordy", "difficulty": 7, - "slug": "kindergarten-garden", "topics": [ "arrays", - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "strings", - "text-formatting" - ], - "unlocked_by": "wordy", - "uuid": "2702ac90-0be2-43a2-91b6-7256a25fec87" + "text_formatting" + ] }, { + "slug": "binary-search", + "uuid": "5991c379-f033-4b46-9702-6b7fd03640e8", "core": false, + "unlocked_by": "linked-list", "difficulty": 7, - "slug": "binary-search", "topics": [ "algorithms", "arrays", - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "recursion" - ], - "unlocked_by": "linked-list", - "uuid": "5991c379-f033-4b46-9702-6b7fd03640e8" + ] }, { + "slug": "binary-search-tree", + "uuid": "865806e0-950f-49a5-a6e5-26472b90ab85", "core": false, + "unlocked_by": "linked-list", "difficulty": 6, - "slug": "binary-search-tree", "topics": [ "algorithms", - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "recursion" - ], - "unlocked_by": "binary-search", - "uuid": "865806e0-950f-49a5-a6e5-26472b90ab85" + ] }, { + "slug": "robot-simulator", + "uuid": "00002977-ea1e-45e2-b66e-09d793b5c1ad", "core": false, + "unlocked_by": "wordy", "difficulty": 5, - "slug": "robot-simulator", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling", "games", "parsing", "strings" - ], - "unlocked_by": "wordy", - "uuid": "00002977-ea1e-45e2-b66e-09d793b5c1ad" + ] }, { + "slug": "nth-prime", + "uuid": "8fa51380-ec2c-4806-8833-cf543579de17", "core": false, + "unlocked_by": "prime-factors", "difficulty": 5, - "slug": "nth-prime", "topics": [ "algorithms", - "control-flow-(conditionals)", - "control-flow-(loops)", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling", "integers", "mathematics" - ], - "unlocked_by": "prime-factors", - "uuid": "8fa51380-ec2c-4806-8833-cf543579de17" + ] }, { + "slug": "palindrome-products", + "uuid": "fde83f66-d927-48f8-a599-efb98927f0b1", "core": false, + "unlocked_by": "prime-factors", "difficulty": 7, - "slug": "palindrome-products", "topics": [ "algorithms", - "control-flow-(conditionals)", - "control-flow-(loops)", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling", "integers", "mathematics" - ], - "unlocked_by": "prime-factors", - "uuid": "fde83f66-d927-48f8-a599-efb98927f0b1" + ] }, { + "slug": "say", + "uuid": "01d286f6-5f29-4d4b-a4de-e217a4833bfa", "core": false, + "unlocked_by": "bob", "difficulty": 6, - "slug": "say", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling", "integers", "mathematics", "strings", - "text-formatting" - ], - "unlocked_by": "bob", - "uuid": "01d286f6-5f29-4d4b-a4de-e217a4833bfa" + "text_formatting" + ] }, { + "slug": "custom-set", + "uuid": "d4ec15c4-2742-493b-97fe-9d5121f0b659", "core": false, + "unlocked_by": "linked-list", "difficulty": 6, - "slug": "custom-set", "topics": [ "arrays", - "control-flow-(conditionals)", - "control-flow-(loops)", - "data-structures", + "control_flow_conditionals", + "control_flow_loops", + "data_structures", "equality", "lists", "recursion", "sets" - ], - "unlocked_by": "linked-list", - "uuid": "d4ec15c4-2742-493b-97fe-9d5121f0b659" + ] }, { + "slug": "sum-of-multiples", + "uuid": "f30463c4-9d8c-4238-a691-e594291b4425", "core": false, + "unlocked_by": "prime-factors", "difficulty": 5, - "slug": "sum-of-multiples", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "integers", "lists" - ], - "unlocked_by": "prime-factors", - "uuid": "f30463c4-9d8c-4238-a691-e594291b4425" + ] }, { + "slug": "queen-attack", + "uuid": "fefcfeba-59ec-4c63-a562-374201ee39a7", "core": false, + "unlocked_by": null, "difficulty": 8, - "slug": "queen-attack", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "equality", - "exception-handling", - "optional-values", + "exception_handling", + "optional_values", "parsing", - "text-formatting" - ], - "unlocked_by": null, - "uuid": "fefcfeba-59ec-4c63-a562-374201ee39a7" + "text_formatting" + ] }, { + "slug": "saddle-points", + "uuid": "98cbae4f-78b6-4745-b922-39e8db9a12bb", "core": false, + "unlocked_by": "matrix", "difficulty": 6, - "slug": "saddle-points", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "equality", - "exception-handling", + "exception_handling", "integers", "mathematics", "matrices", - "optional-values", + "optional_values", "parsing" - ], - "unlocked_by": "matrix", - "uuid": "98cbae4f-78b6-4745-b922-39e8db9a12bb" + ] }, { + "slug": "ocr-numbers", + "uuid": "759618b1-7ccc-46cd-889d-aea58ec88756", "core": false, + "unlocked_by": "matrix", "difficulty": 5, - "slug": "ocr-numbers", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "equality", - "exception-handling", + "exception_handling", "integers", "parsing", - "text-formatting" - ], - "unlocked_by": "matrix", - "uuid": "759618b1-7ccc-46cd-889d-aea58ec88756" + "text_formatting" + ] }, { + "slug": "meetup", + "uuid": "86b1b6ba-c1fe-492d-a7ec-c22c525b4da8", "core": false, + "unlocked_by": "gigasecond", "difficulty": 7, - "slug": "meetup", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", + "control_flow_conditionals", + "control_flow_loops", "dates", "equality", - "exception-handling", + "exception_handling", "time" - ], - "unlocked_by": "gigasecond", - "uuid": "86b1b6ba-c1fe-492d-a7ec-c22c525b4da8" + ] }, { + "slug": "bracket-push", + "uuid": "25099f87-5c3b-4a8a-b648-4639d1e9fa84", "core": false, + "unlocked_by": "pangram", "difficulty": 3, - "slug": "bracket-push", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling", "parsing", "strings" - ], - "unlocked_by": "pangram", - "uuid": "25099f87-5c3b-4a8a-b648-4639d1e9fa84" + ] }, { + "slug": "two-bucket", + "uuid": "4c857b17-33b0-47fa-b981-6b2fe4e394a1", "core": false, + "unlocked_by": "grade-school", "difficulty": 6, - "slug": "two-bucket", "topics": [ "algorithms", "arrays", - "control-flow-(conditionals)", - "control-flow-(loops)", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling", "games", "parsing" - ], - "unlocked_by": "grade-school", - "uuid": "4c857b17-33b0-47fa-b981-6b2fe4e394a1" + ] }, { + "slug": "bowling", + "uuid": "c168fe1f-f84e-46e6-91fc-7553d048a4e9", "core": false, + "unlocked_by": "grade-school", "difficulty": 8, - "slug": "bowling", "topics": [ "arrays", - "control-flow-(conditionals)", - "control-flow-(loops)", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling", "games", "parsing", - "text-formatting" - ], - "unlocked_by": "grade-school", - "uuid": "c168fe1f-f84e-46e6-91fc-7553d048a4e9" + "text_formatting" + ] }, { + "slug": "diamond", + "uuid": "04a4ef78-5b61-454f-8c37-798875fb4956", "core": false, + "unlocked_by": "pascals-triangle", "difficulty": 5, - "slug": "diamond", "topics": [ "arrays", - "control-flow-(conditionals)", - "control-flow-(loops)", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling", "games", "parsing", - "text-formatting" - ], - "unlocked_by": "pascals-triangle", - "uuid": "04a4ef78-5b61-454f-8c37-798875fb4956" + "text_formatting" + ] }, { + "slug": "all-your-base", + "uuid": "cdfcec62-f2f3-4408-ad2c-8b5e1e56e791", "core": false, + "unlocked_by": "binary", "difficulty": 5, - "slug": "all-your-base", "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", - "exception-handling", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling", "integers", "mathematics", "parsing" - ], - "unlocked_by": "binary", - "uuid": "cdfcec62-f2f3-4408-ad2c-8b5e1e56e791" + ] }, { + "slug": "minesweeper", + "uuid": "22fa5ab4-935b-44cc-b055-9803214ae5f3", "core": false, + "unlocked_by": null, "difficulty": 7, - "slug": "minesweeper", "topics": [ "algorithms", "arrays", "games" - ], - "unlocked_by": null, - "uuid": "22fa5ab4-935b-44cc-b055-9803214ae5f3" + ] }, { + "slug": "alphametics", + "uuid": "42a7fd83-4508-403c-8b5e-f0a3126fac8a", "core": false, + "unlocked_by": "grade-school", "difficulty": 7, - "slug": "alphametics", "topics": [ "algorithms", "games" - ], - "unlocked_by": "grade-school", - "uuid": "42a7fd83-4508-403c-8b5e-f0a3126fac8a" + ] }, { + "slug": "simple-linked-list", + "uuid": "c21ab6e8-b845-49d0-a2f6-1c89c7a07626", "core": false, + "unlocked_by": "linked-list", "difficulty": 8, - "slug": "simple-linked-list", "topics": [ "arrays", - "data-structures", + "data_structures", "lists" - ], - "unlocked_by": "linked-list", - "uuid": "c21ab6e8-b845-49d0-a2f6-1c89c7a07626" + ] }, { - "uuid": "833bd7c7-d3d8-45fd-a218-12dea646065d", "slug": "diffie-hellman", + "uuid": "833bd7c7-d3d8-45fd-a218-12dea646065d", "core": false, "unlocked_by": "simple-cipher", "difficulty": 3, "topics": [ - "Control-flow (conditionals)", - "Control-flow (loops)", - "Algorithms", - "Arrays", - "Exception handling" + "algorithms", + "arrays", + "control_flow_conditionals", + "control_flow_loops", + "exception_handling" ] }, { - "core" : false, - "difficulty" : 8, - "slug" : "change", - "topics": [ - "Algorithms", - "Mathematics", - "Performance", - "Searching" - ], + "slug": "change", + "uuid": "910fe904-7e3c-11e7-bb31-be2e44b06b34", + "core": false, "unlocked_by": "prime-factors", - "uuid" : "910fe904-7e3c-11e7-bb31-be2e44b06b34" + "difficulty": 8, + "topics": [ + "algorithms", + "mathematics", + "performance", + "searching" + ] }, { - "core" : false, - "difficulty" : 1, - "slug" : "collatz-conjecture", - "topics": [ - "Control-flow (loops)", - "Control-flow (conditionals)", - "Recursion", - "Integers", - "Algorithms", - "Mathematics" - ], - "unlocked_by": "null", - "uuid" : "fd435dad-311a-4c40-9868-70863455831e" + "slug": "connect", + "uuid": "3b779cb8-9544-4e0d-a306-e5478d741be7", + "core": false, + "unlocked_by": "grade-school", + "difficulty": 7, + "topics": [ + "arrays", + "control_flow_conditionals", + "control_flow_loops", + "games", + "maps", + "parsing" + ] + }, + { + "slug": "collatz-conjecture", + "uuid": "fd435dad-311a-4c40-9868-70863455831e", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "algorithms", + "control_flow_conditionals", + "control_flow_loops", + "integers", + "mathematics", + "recursion" + ] }, { - "deprecated": true, "slug": "nucleotide-count", - "uuid": "1b53340d-ea40-44ee-bf2e-42e516704e7c" + "uuid": "1b53340d-ea40-44ee-bf2e-42e516704e7c", + "core": false, + "unlocked_by": null, + "difficulty": 0, + "topics": null, + "deprecated": true }, { - "deprecated": true, "slug": "point-mutations", - "uuid": "e9a6b2ea-a67d-4b75-800d-7b46240094ec" + "uuid": "e9a6b2ea-a67d-4b75-800d-7b46240094ec", + "core": false, + "unlocked_by": null, + "difficulty": 0, + "topics": null, + "deprecated": true }, { - "uuid": "09e10522-9853-11e7-abc4-cec278b6b50a", "slug": "twelve-days", + "uuid": "09e10522-9853-11e7-abc4-cec278b6b50a", "core": false, "unlocked_by": "bob", "difficulty": 4, "topics": [ - "Control-flow (conditionals)", - "Control-flow (loops)", - "Polymorphism", - "Strings", - "Pattern recognition", - "Regular expressions" + "control_flow_conditionals", + "control_flow_loops", + "pattern_recognition", + "strings" ] }, { + "slug": "transpose", + "uuid": "7c024853-0540-473d-b2d9-cad84953c00f", "core": false, + "unlocked_by": "matrix", "difficulty": 1, - "slug": "transpose", "topics": [ - "loops", "arrays", "lists", + "loops", "matrices", "strings", "text_formatting" - ], - "unlocked_by": "matrix", - "uuid": "7c024853-0540-473d-b2d9-cad84953c00f" + ] }, { - "uuid": "52c775a4-7ddb-4cba-8a78-8544220bd1b6", "slug": "protein-translation", + "uuid": "52c775a4-7ddb-4cba-8a78-8544220bd1b6", "core": false, "unlocked_by": null, "difficulty": 1, "topics": [ - "control-flow-(conditionals)", - "control-flow-(loops)", - "strings", - "algorithms" + "algorithms", + "control_flow_conditionals", + "control_flow_loops", + "strings" ] }, { - "uuid": "f4a3d66a-04a8-3e80-6c9a-8a573ccb26fd9ed1d5c", "slug": "zipper", + "uuid": "f4a3d66a-04a8-3e80-6c9a-8a573ccb26fd9ed1d5c", "core": false, "unlocked_by": null, "difficulty": 8, @@ -1135,9 +1224,65 @@ "searching", "trees" ] + }, + { + "slug": "isbn-verifier", + "uuid": "8740af44-002c-4716-a759-a68ae4c68737", + "core": false, + "unlocked_by": "bob", + "difficulty": 4, + "topics": [ + "conditionals", + "loops", + "pattern_matching", + "strings" + ] + }, + { + "slug": "forth", + "uuid": "b3dbc935-536e-4910-994d-4a519b511b6a", + "core": false, + "unlocked_by": "matrix", + "difficulty": 8, + "topics": [ + "domain_specific_languages", + "parsing", + "stacks" + ] + }, + { + "slug": "variable-length-quantity", + "uuid": "f82e470d-0bcc-4eba-b9b0-8a0c50a6fd19", + "core": false, + "unlocked_by": "grade-school", + "difficulty": 5, + "topics": [ + "bitwise_operations", + "transforming" + ] + }, + { + "slug": "rectangles", + "uuid": "cb09212c-f2ae-4acf-9177-6c7f42594c1d", + "core": false, + "unlocked_by": "grade-school", + "difficulty": 6, + "topics": [ + "parsing", + "pattern_recognition", + "searching" + ] + }, + { + "slug": "armstrong-numbers", + "uuid": "0e4b628c-870d-446b-a400-3cc72457f2bc", + "core": false, + "unlocked_by": null, + "difficulty": 2, + "topics": [ + "algorithms", + "mathematics" + ] } - ], - "foregone": [], - "language": "JavaScript", - "test_pattern": ".*[.]spec[.]js$" + ] } diff --git a/config/exercise_readme.go.tmpl b/config/exercise_readme.go.tmpl index 2b26f494..730bb47c 100644 --- a/config/exercise_readme.go.tmpl +++ b/config/exercise_readme.go.tmpl @@ -4,10 +4,32 @@ {{- with .Hints }} {{ . }} {{ end }} -{{- with .TrackInsert }} -{{ . }} -{{ end }} -{{- with .Spec.Credits -}} +## Setup + +Go through the setup instructions for JavaScript to install the + necessary dependencies: + +http://exercism.io/languages/javascript/installation + +## Running the test suite + +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: + +```sh +npm install -g jasmine +``` + +Run the test suite from the exercise directory with: + +```sh +jasmine {{ .Spec.Slug }}.spec.js +``` + +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. +{{ with .Spec.Credits }} ## Source {{ . }} diff --git a/config/maintainers.json b/config/maintainers.json index 59962c14..48b19c6a 100644 --- a/config/maintainers.json +++ b/config/maintainers.json @@ -1,85 +1,5 @@ { "docs_url": "https://github.com/exercism/docs/blob/master/maintaining-a-track/maintainer-configuration.md", "maintainers": [ - { - "alumnus": false, - "avatar_url": null, - "bio": null, - "github_username": "ireddick", - "link_text": null, - "link_url": null, - "name": null, - "show_on_website": false - }, - { - "alumnus": false, - "avatar_url": null, - "bio": "I'm a Web Developer with a passion for taking code that is hard to maintain and cleaning, refactoring, and bringing it back into a manageable state", - "github_username": "rchavarria", - "link_text": "Here is where I blog", - "link_url": "https://rchavarria.github.io/", - "name": "Rubén Chavarría", - "show_on_website": true - }, - { - "alumnus": false, - "avatar_url": null, - "bio": "Brazilian full-stack web developer. Mentor at Thinkful", - "github_username": "joelwallis", - "link_text": null, - "link_url": null, - "name": null, - "show_on_website": true - }, - { - "alumnus": false, - "avatar_url": null, - "bio": null, - "github_username": "drueck", - "link_text": null, - "link_url": null, - "name": null, - "show_on_website": false - }, - { - "alumnus": false, - "avatar_url": null, - "bio": null, - "github_username": "tejasbubane", - "link_text": null, - "link_url": null, - "name": null, - "show_on_website": false - }, - { - "alumnus": false, - "avatar_url": null, - "bio": null, - "github_username": "matthewmorgan", - "link_text": null, - "link_url": null, - "name": null, - "show_on_website": false - }, - { - "alumnus": false, - "avatar_url": null, - "bio": null, - "github_username": "mixolidia", - "link_text": null, - "link_url": null, - "name": null, - "show_on_website": false - }, - { - "alumnus": false, - "avatar_url": null, - "bio": null, - "github_username": "ZacharyRSmith", - "link_text": null, - "link_url": null, - "name": null, - "show_on_website": false - } ] } diff --git a/docs/EXERCISE_README_INSERT.md b/docs/EXERCISE_README_INSERT.md deleted file mode 100644 index 00fd308e..00000000 --- a/docs/EXERCISE_README_INSERT.md +++ /dev/null @@ -1,22 +0,0 @@ -## 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 Hello World exercise: - - jasmine hello-world.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`. diff --git a/docs/LEARNING.md b/docs/LEARNING.md index 0e0322cb..462c8cb2 100644 --- a/docs/LEARNING.md +++ b/docs/LEARNING.md @@ -1,4 +1,4 @@ -* [Eloquent JavaScript: A Modern Introduction to Programming (2nd Ed.)](http://eloquentjavascript.net) +* [Eloquent JavaScript: A Modern Introduction to Programming](http://eloquentjavascript.net) * [JavaScript: The Good Parts](http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742) * [Crockford on JavaScript](http://javascript.crockford.com/) * [idiomatic.js: Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwaldron/idiomatic.js) diff --git a/exercises/accumulate/README.md b/exercises/accumulate/README.md index 1f8e999f..0588b985 100644 --- a/exercises/accumulate/README.md +++ b/exercises/accumulate/README.md @@ -25,31 +25,31 @@ Keep your hands off that collect/map/fmap/whatchamacallit functionality provided by your standard library! Solve this one yourself using other basic tools instead. -Lisp specific: it's perfectly fine to use `MAPCAR` or the equivalent, -as this is idiomatic Lisp, not a library function. - ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine accumulate.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/accumulate/example.js b/exercises/accumulate/example.js index 18274805..e36fb748 100644 --- a/exercises/accumulate/example.js +++ b/exercises/accumulate/example.js @@ -1,4 +1,4 @@ -var accumulate = module.exports = function (list, accumulator) { +module.exports = function (list, accumulator) { var out = []; var idx = -1; var end = Array.isArray(list) ? list.length : 0; @@ -9,4 +9,3 @@ var accumulate = module.exports = function (list, accumulator) { return out; }; - diff --git a/exercises/acronym/README.md b/exercises/acronym/README.md index 3cc46d74..8fefa5b9 100644 --- a/exercises/acronym/README.md +++ b/exercises/acronym/README.md @@ -7,29 +7,31 @@ Techies love their TLA (Three Letter Acronyms)! Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG). - ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine acronym.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/acronym/example.js b/exercises/acronym/example.js index d50a50a6..1618d203 100644 --- a/exercises/acronym/example.js +++ b/exercises/acronym/example.js @@ -2,7 +2,8 @@ module.exports = { parse: function (phrase) { return phrase.match(/[A-Z]+[a-z]*|[a-z]+/g) .reduce(function (acronym, word) { - return acronym += word[0].toUpperCase(); + var returnAcronym = acronym + word[0].toUpperCase(); + return returnAcronym; }, ''); } }; diff --git a/exercises/all-your-base/README.md b/exercises/all-your-base/README.md index 5971b557..d18b0258 100644 --- a/exercises/all-your-base/README.md +++ b/exercises/all-your-base/README.md @@ -6,6 +6,7 @@ Implement general base conversion. Given a number in base **a**, represented as a sequence of digits, convert it to base **b**. ## Note + - Try to implement the conversion yourself. Do not use something else to perform the conversion for you. @@ -28,32 +29,33 @@ The number 1120, *in base 3*, means: I think you got the idea! - *Yes. Those three numbers above are exactly the same. Congratulations!* ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript - -## Making the Test Suite Pass +Go through the setup instructions for JavaScript to install the + necessary dependencies: -Execute the tests with: +http://exercism.io/languages/javascript/installation - jasmine .spec.js +## Running the test suite -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine hello-world.spec.js +```sh +npm install -g jasmine +``` -In many test suites all but the first test have been skipped. +Run the test suite from the exercise directory with: -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +```sh +jasmine all-your-base.spec.js +``` +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## 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/allergies/README.md b/exercises/allergies/README.md index af0072d6..179a7f58 100644 --- a/exercises/allergies/README.md +++ b/exercises/allergies/README.md @@ -29,29 +29,31 @@ allergens that score 256, 512, 1024, etc.). Your program should ignore those components of the score. For example, if the allergy score is 257, your program should only report the eggs (1) allergy. - ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine allergies.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/alphametics/README.md b/exercises/alphametics/README.md index d96936f2..bc3ff2ec 100644 --- a/exercises/alphametics/README.md +++ b/exercises/alphametics/README.md @@ -7,7 +7,7 @@ letters in words are replaced with numbers. For example `SEND + MORE = MONEY`: -``` +```text S E N D M O R E + ----------- @@ -16,7 +16,7 @@ M O N E Y Replacing these with valid numbers gives: -``` +```text 9 5 6 7 1 0 8 5 + ----------- @@ -33,27 +33,29 @@ Write a function to solve alphametics puzzles. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: - - jasmine hello-world.spec.js +```sh +npm install -g jasmine +``` -In many test suites all but the first test have been skipped. +Run the test suite from the exercise directory with: -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +```sh +jasmine alphametics.spec.js +``` +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## 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/alphametics/example.js b/exercises/alphametics/example.js index 5467cf24..0c4a8f7f 100644 --- a/exercises/alphametics/example.js +++ b/exercises/alphametics/example.js @@ -53,21 +53,21 @@ function testNumbers(numbers, puzzleParts, firstLetters) { } var replaceRegex = new RegExp('[' + keys.join('') + ']', 'g'); - puzzleParts = puzzleParts.join(',') + var puzzlePartsJoined = puzzleParts.join(',') .replace(replaceRegex, function (input) { return numbers[input]; }) .split(',') - .map(function (t) {return parseInt(t);}); + .map(function (t) {return parseInt(t, 10);}); - var total = puzzleParts.slice(puzzleParts.length - 1)[0]; - return total === puzzleParts - .slice(0, puzzleParts.length - 1) + var total = puzzlePartsJoined.slice(puzzlePartsJoined.length - 1)[0]; + return total === puzzlePartsJoined + .slice(0, puzzlePartsJoined.length - 1) .reduce(function (acc, val) { return acc + val; }, 0); } function getPermutations(inputArr) { var results = []; function permute(arr, memo) { - var cur, memo = memo || []; + var cur = memo; for (var i = 0; i < arr.length; i++) { cur = arr.splice(i, 1); if (arr.length === 0) { @@ -78,11 +78,15 @@ function getPermutations(inputArr) { } return results; } - return permute(inputArr); + return permute(inputArr, []); } function getNumberCombinations(set, k) { - var i, j, combs, head, tailcombs; + var i; + var j; + var combs; + var head; + var tailcombs; if (k > set.length || k <= 0) { return []; } @@ -104,4 +108,4 @@ function getNumberCombinations(set, k) { return combs; } -module.exports = solve; +module.exports = solve; diff --git a/exercises/anagram/README.md b/exercises/anagram/README.md index f9b4bf5c..9473855e 100644 --- a/exercises/anagram/README.md +++ b/exercises/anagram/README.md @@ -8,26 +8,29 @@ Given `"listen"` and a list of candidates like `"enlists" "google" ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine anagram.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/anagram/example.js b/exercises/anagram/example.js index f1d77dc4..2e1cee2e 100644 --- a/exercises/anagram/example.js +++ b/exercises/anagram/example.js @@ -4,8 +4,8 @@ function Anagram(word) { this.word = word; } -Anagram.prototype.matches = function (words) { - words = Array.isArray(words) ? words : [].slice.call(arguments, 0); +Anagram.prototype.matches = function (wordList) { + var words = Array.isArray(wordList) ? wordList : [].slice.call(arguments, 0); return words.filter(function (candidate) { return !sameWord(this.word, candidate) && isAnagram(this.word, candidate); diff --git a/exercises/armstrong-numbers/README.md b/exercises/armstrong-numbers/README.md new file mode 100644 index 00000000..f0714aa7 --- /dev/null +++ b/exercises/armstrong-numbers/README.md @@ -0,0 +1,46 @@ +# Armstrong Numbers + +An [Armstrong number](https://en.wikipedia.org/wiki/Narcissistic_number) is a number that is the sum of its own digits each raised to the power of the number of digits. + +For example: + +- 9 is an Armstrong number, because `9 = 9^1 = 9` +- 10 is *not* an Armstrong number, because `10 != 1^2 + 0^2 = 2` +- 153 is an Armstrong number, because: `153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153` +- 154 is *not* an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190` + +Write some code to determine whether a number is an Armstrong number. + +## Setup + +Go through the setup instructions for JavaScript to install the + necessary dependencies: + +http://exercism.io/languages/javascript/installation + +## Running the test suite + +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: + +```sh +npm install -g jasmine +``` + +Run the test suite from the exercise directory with: + +```sh +jasmine armstrong-numbers.spec.js +``` + +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. + +## Source + +Wikipedia [Narcissistic number](https://en.wikipedia.org/wiki/Narcissistic_number) + +## 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/armstrong-numbers/armstrong-numbers.spec.js b/exercises/armstrong-numbers/armstrong-numbers.spec.js new file mode 100644 index 00000000..9f250fac --- /dev/null +++ b/exercises/armstrong-numbers/armstrong-numbers.spec.js @@ -0,0 +1,43 @@ +var ArmstrongNumber = require('./armstrong-numbers'); + +describe('ArmstrongNumber', function () { + it('Single digit numbers are Armstrong numbers', function () { + var input = 5; + expect(ArmstrongNumber.validate(input)).toBe(true); + }); + + xit('There are no 2 digit Armstrong numbers', function () { + var input = 10; + expect(ArmstrongNumber.validate(input)).toBe(false); + }); + + xit('Three digit number that is an Armstrong number', function () { + var input = 153; + expect(ArmstrongNumber.validate(input)).toBe(true); + }); + + xit('Three digit number that is not an Armstrong number', function () { + var input = 100; + expect(ArmstrongNumber.validate(input)).toBe(false); + }); + + xit('Four digit number that is an Armstrong number', function () { + var input = 9474; + expect(ArmstrongNumber.validate(input)).toBe(true); + }); + + xit('Four digit number that is not an Armstrong number', function () { + var input = 9475; + expect(ArmstrongNumber.validate(input)).toBe(false); + }); + + xit('Seven digit number that is an Armstrong number', function () { + var input = 9926315; + expect(ArmstrongNumber.validate(input)).toBe(true); + }); + + xit('Seven digit number that is not an Armstrong number', function () { + var input = 9926314; + expect(ArmstrongNumber.validate(input)).toBe(false); + }); +}); diff --git a/exercises/armstrong-numbers/example.js b/exercises/armstrong-numbers/example.js new file mode 100644 index 00000000..c0652924 --- /dev/null +++ b/exercises/armstrong-numbers/example.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = { + validate: function (input) { + var digits = String(input).split(''); + var sum = digits.reduce(function (total, current) { + return total + Math.pow(current, digits.length); + }, 0); + return sum === input; + } +}; diff --git a/exercises/atbash-cipher/README.md b/exercises/atbash-cipher/README.md index 57634176..a34b50ab 100644 --- a/exercises/atbash-cipher/README.md +++ b/exercises/atbash-cipher/README.md @@ -9,7 +9,7 @@ letter, the second with the second-last, and so on. An Atbash cipher for the Latin alphabet would be as follows: -```plain +```text Plain: abcdefghijklmnopqrstuvwxyz Cipher: zyxwvutsrqponmlkjihgfedcba ``` @@ -23,32 +23,36 @@ being 5 letters, and punctuation is excluded. This is to make it harder to guess things based on word boundaries. ## Examples + - Encoding `test` gives `gvhg` - Decoding `gvhg` gives `test` - Decoding `gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt` gives `thequickbrownfoxjumpsoverthelazydog` ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine atbash-cipher.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/beer-song/README.md b/exercises/beer-song/README.md index 57089d1d..ffd71e31 100644 --- a/exercises/beer-song/README.md +++ b/exercises/beer-song/README.md @@ -1,10 +1,10 @@ # Beer Song -Produce the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall. +Recite the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall. Note that not all verses are identical. -```plain +```text 99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around, 98 bottles of beer on the wall. @@ -322,26 +322,29 @@ experiment make the code better? Worse? Did you learn anything from it? ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js - -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine beer-song.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/binary-search-tree/README.md b/exercises/binary-search-tree/README.md index 5b864ebc..798ea8f2 100644 --- a/exercises/binary-search-tree/README.md +++ b/exercises/binary-search-tree/README.md @@ -55,26 +55,29 @@ And if we then added 1, 5, and 7, it would look like this ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine binary-search-tree.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/binary-search-tree/example.js b/exercises/binary-search-tree/example.js index 6b4665b6..edc3af96 100644 --- a/exercises/binary-search-tree/example.js +++ b/exercises/binary-search-tree/example.js @@ -2,8 +2,8 @@ function BinarySearchTree(data) { this.data = data; - this.left = undefined; - this.right = undefined; + this.left = null; + this.right = null; } BinarySearchTree.prototype.insert = function (value) { diff --git a/exercises/binary-search/README.md b/exercises/binary-search/README.md index 2aa09ad1..c3f4cb4c 100644 --- a/exercises/binary-search/README.md +++ b/exercises/binary-search/README.md @@ -36,26 +36,29 @@ A binary search is a dichotomic divide and conquer search algorithm. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine binary-search.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/binary-search/example.js b/exercises/binary-search/example.js index a4e6095c..a1fd178f 100644 --- a/exercises/binary-search/example.js +++ b/exercises/binary-search/example.js @@ -18,7 +18,7 @@ function BinarySearch(array) { function recursiveSearch(array, value, start, end) { - if (start == end) return -1; + if (start === end) return -1; var mid = Math.floor((start + end) / 2); diff --git a/exercises/binary/README.md b/exercises/binary/README.md index c41024b0..363c47bd 100644 --- a/exercises/binary/README.md +++ b/exercises/binary/README.md @@ -7,10 +7,12 @@ string, your program should produce a decimal output. The program should handle invalid inputs. ## Note + - Implement the conversion yourself. Do not use something else to perform the conversion for you. ## About Binary (Base-2) + Decimal is a base-10 system. A number 23 in base 10 notation can be understood @@ -30,26 +32,29 @@ So: `101 => 1*2^2 + 0*2^1 + 1*2^0 => 1*4 + 0*2 + 1*1 => 4 + 1 => 5 base 10`. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine binary.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/bob/README.md b/exercises/bob/README.md index b53ec785..ee9c8adb 100644 --- a/exercises/bob/README.md +++ b/exercises/bob/README.md @@ -6,6 +6,8 @@ Bob answers 'Sure.' if you ask him a question. He answers 'Whoa, chill out!' if you yell at him. +He answers 'Calm down, I know what I'm doing!' if you yell a question at him. + He says 'Fine. Be that way!' if you address him without actually saying anything. @@ -13,26 +15,29 @@ He answers 'Whatever.' to anything else. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine bob.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/bob/bob.spec.js b/exercises/bob/bob.spec.js index d8555e65..fc017cd1 100644 --- a/exercises/bob/bob.spec.js +++ b/exercises/bob/bob.spec.js @@ -45,7 +45,7 @@ describe('Bob', function () { xit('forceful questions', function () { var result = bob.hey('WHAT THE HELL WERE YOU THINKING?'); - expect(result).toEqual('Whoa, chill out!'); + expect(result).toEqual("Calm down, I know what I'm doing!"); }); xit('shouting numbers', function () { diff --git a/exercises/bob/example.js b/exercises/bob/example.js index 7826975f..b7fa2913 100644 --- a/exercises/bob/example.js +++ b/exercises/bob/example.js @@ -18,6 +18,9 @@ function Bob() { if (isSilence(message)) { return 'Fine. Be that way!'; } else if (isShouting(message)) { + if (isAQuestion(message)) { + return "Calm down, I know what I'm doing!"; + } return 'Whoa, chill out!'; } else if (isAQuestion(message)) { return 'Sure.'; diff --git a/exercises/bowling/README.md b/exercises/bowling/README.md index b8342c33..d1d52f8d 100644 --- a/exercises/bowling/README.md +++ b/exercises/bowling/README.md @@ -2,19 +2,29 @@ Score a bowling game. -Bowling is game where players roll a heavy ball to knock down pins +Bowling is a game where players roll a heavy ball to knock down pins arranged in a triangle. Write code to keep track of the score of a game of bowling. ## Scoring Bowling -The game consists of 10 frames. A frame is composed of one or two ball throws with 10 pins standing at frame initialization. There are three cases for the tabulation of a frame. +The game consists of 10 frames. A frame is composed of one or two ball +throws with 10 pins standing at frame initialization. There are three +cases for the tabulation of a frame. -* An open frame is where a score of less than 10 is recorded for the frame. In this case the score for the frame is the number of pins knocked down. +* An open frame is where a score of less than 10 is recorded for the + frame. In this case the score for the frame is the number of pins + knocked down. -* A spare is where all ten pins are knocked down after the second throw. The total value of a spare is 10 plus the number of pins knocked down in their next throw. +* A spare is where all ten pins are knocked down by the second + throw. The total value of a spare is 10 plus the number of pins + knocked down in their next throw. -* A strike is where all ten pins are knocked down after the first throw. The total value of a strike is 10 plus the number of pins knocked down in their next two throws. If a strike is immediately followed by a second strike, then we can not total the value of first strike until they throw the ball one more time. +* A strike is where all ten pins are knocked down by the first + throw. The total value of a strike is 10 plus the number of pins + knocked down in the next two throws. If a strike is immediately + followed by a second strike, then the value of the first strike + cannot be determined until the ball is thrown one more time. Here is a three frame example: @@ -30,7 +40,11 @@ Frame 3 is (9 + 0) = 9 This means the current running total is 48. -The tenth frame in the game is a special case. If someone throws a strike or a spare then they get a fill ball. Fill balls exist to calculate the total of the 10th frame. Scoring a strike or spare on the fill ball does not give the player more fill balls. The total value of the 10th frame is the total number of pins knocked down. +The tenth frame in the game is a special case. If someone throws a +strike or a spare then they get a fill ball. Fill balls exist to +calculate the total of the 10th frame. Scoring a strike or spare on +the fill ball does not give the player more fill balls. The total +value of the 10th frame is the total number of pins knocked down. For a tenth frame of X1/ (strike and a spare), the total value is 20. @@ -48,26 +62,29 @@ support two operations: ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine bowling.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/bowling/bowling.spec.js b/exercises/bowling/bowling.spec.js index 881b1b45..c78b2f9d 100644 --- a/exercises/bowling/bowling.spec.js +++ b/exercises/bowling/bowling.spec.js @@ -1,148 +1,228 @@ var Bowling = require('./bowling'); describe('Bowling', function () { + function previousRolls(bowling, rolls) { + for (var i = 0; i < rolls.length; i++) { + bowling.roll(rolls[i]); + } + } describe('Check game can be scored correctly.', function () { it('should be able to score a game with all gutterballs', function () { var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - expect(new Bowling(rolls).score()).toEqual(0); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(0); }); - xit('should be able to score a game with all open frames', function () { + xit('should be able to score a game with no strikes or spares', function () { var rolls = [3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6]; - expect(new Bowling(rolls).score()).toEqual(90); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(90); }); xit('a spare followed by zeros is worth ten points', function () { var rolls = [6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - expect(new Bowling(rolls).score()).toEqual(10); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(10); }); xit('points scored in the roll after a spare are counted twice', function () { var rolls = [6, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - expect(new Bowling(rolls).score()).toEqual(16); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(16); }); - xit('consecutive spares each get a one roll bonus', function () { + xit('consecutive spares each get a one-roll bonus', function () { var rolls = [5, 5, 3, 7, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - expect(new Bowling(rolls).score()).toEqual(31); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(31); }); - xit('should allow fill ball when the last frame is a spare', function () { + xit('should allow fill ball the last frame is a spare', function () { var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 7]; - expect(new Bowling(rolls).score()).toEqual(17); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(17); }); - xit('a strike earns ten points in a frame with a single roll', function () { + xit('a strike earns ten points in a frame with a single roll', function () { var rolls = [10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - expect(new Bowling(rolls).score()).toEqual(10); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(10); }); xit('points scored in the two rolls after a strike are counted twice as a bonus', function () { var rolls = [10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - expect(new Bowling(rolls).score()).toEqual(26); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(26); }); xit('should be able to score multiple strikes in a row', function () { var rolls = [10, 10, 10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - expect(new Bowling(rolls).score()).toEqual(81); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(81); }); xit('should allow fill balls when the last frame is a strike', function () { var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 7, 1]; - expect(new Bowling(rolls).score()).toEqual(18); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(18); }); - xit('rolling a spare with the two roll bonus does not get a bonus roll', function () { + xit('rolling a spare with the two-roll bonus does not get a bonus roll', function () { var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 7, 3]; - expect(new Bowling(rolls).score()).toEqual(20); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(20); }); - xit('strikes with the two roll bonus do not get bonus rolls', function () { + xit('strikes with the two-roll bonus do not get bonus rolls', function () { var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10]; - expect(new Bowling(rolls).score()).toEqual(30); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(30); }); - xit('a strike with the one roll bonus after a spare in the last frame does not get a bonus', function () { + xit('a strike with the one-roll bonus after a spare in the last frame does not get a bonus', function () { var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 10]; - expect(new Bowling(rolls).score()).toEqual(20); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(20); }); xit('should be able to score a perfect game', function () { var rolls = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]; - expect(new Bowling(rolls).score()).toEqual(300); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(300); }); }); describe('Check game rules.', function () { - xit('rolls can not score negative points', function () { - var rolls = [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - expect(function () { new Bowling(rolls).score(); }).toThrow( - new Error('Pins must have a value from 0 to 10')); + xit('rolls cannot score negative points', function () { + var bowling = new Bowling(); + expect(function () {bowling.roll(-1);}).toThrow(new Error('Negative roll is invalid')); }); - xit('a roll can not score more than 10 points', function () { - var rolls = [11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - expect(function () { new Bowling(rolls).score(); }).toThrow( - new Error('Pins must have a value from 0 to 10')); + xit('a roll cannot score more than 10 points', function () { + var bowling = new Bowling(); + expect(function () {bowling.roll(11);}).toThrow( new Error('Pin count exceeds pins on the lane')); }); - xit('two rolls in a frame can not score more than 10 points', function () { - var rolls = [5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - expect(function () { new Bowling(rolls).score(); }).toThrow( - new Error('Pin count exceeds pins on the lane')); + xit('two rolls in a frame cannot score more than 10 points', function () { + var bowling = new Bowling(); + bowling.roll(5); + expect(function () {bowling.roll(6);}).toThrow( new Error('Pin count exceeds pins on the lane')); }); - xit('two bonus rolls after a strike in the last frame can not score more than 10 points', function () { - var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 5, 6]; - expect(function () { new Bowling(rolls).score(); }).toThrow( + xit('bonus roll after a strike in the last frame cannot score more than 10 points', function () { + var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10]; + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(function () { bowling.roll(11); }).toThrow( new Error('Pin count exceeds pins on the lane')); }); + xit('two bonus rolls after a strike in the last frame cannot score more than 10 points', function () { + var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 5]; + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(function () {bowling.roll(6);}).toThrow( new Error('Pin count exceeds pins on the lane')); + }); + xit('two bonus rolls after a strike in the last frame can score more than 10 points if one is a strike', function () { var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 6]; - expect(new Bowling(rolls).score()).toEqual(26); + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(bowling.score()).toEqual(26); }); - xit('the second bonus rolls after a strike in the last frame can not be a strike if the first one is not a strike', function () { - var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 6, 10]; - expect(function () { new Bowling(rolls).score(); }).toThrow( + xit('the second bonus roll after a strike in the last frame cannot be a strike if the first one is not a strike', function () { + var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 6]; + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(function () { bowling.roll(10); }).toThrow( new Error('Pin count exceeds pins on the lane')); }); - xit('an unstarted game can not be scored', function () { + xit('the second bonus roll after a strike in the last frame cannot score more than 10 points', function () { + var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10]; + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(function () { bowling.roll(11); }).toThrow( + new Error('Pin count exceeds pins on the lane')); + }); + + xit('an unstarted game cannot be scored', function () { var rolls = []; - expect(function () { new Bowling(rolls).score(); }).toThrow( + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(function () { bowling.score(); }).toThrow( new Error('Score cannot be taken until the end of the game')); }); - xit('an incomplete game can not be scored', function () { + xit('an incomplete game cannot be scored', function () { var rolls = [0, 0]; - expect(function () { new Bowling(rolls).score(); }).toThrow( + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(function () { bowling.score(); }).toThrow( new Error('Score cannot be taken until the end of the game')); }); - xit('a game with more than ten frames and no last frame spare or strike can not be scored', function () { - var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - expect(function () { new Bowling(rolls).score(); }).toThrow( - new Error('Should not be able to roll after game is over')); + xit('cannot roll if game already has 10 frames', function () { + var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(function () { bowling.roll(0); }).toThrow( + new Error('Cannot roll after game is over')); }); xit('bonus rolls for a strike in the last frame must be rolled before score can be calculated', function () { var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10]; - expect(function () { new Bowling(rolls).score(); }).toThrow( + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(function () { bowling.score(); }).toThrow( new Error('Score cannot be taken until the end of the game')); }); xit('both bonus rolls for a strike in the last frame must be rolled before score can be calculated', function () { var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10]; - expect(function () { new Bowling(rolls).score(); }).toThrow( + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(function () {bowling.score(); }).toThrow( new Error('Score cannot be taken until the end of the game')); }); xit('bonus roll for a spare in the last frame must be rolled before score can be calculated', function () { var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3]; - expect(function () { new Bowling(rolls).score(); }).toThrow( + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(function () { bowling.score(); }).toThrow( new Error('Score cannot be taken until the end of the game')); }); + + xit('cannot roll after bonus roll for a spare', function () { + var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 2]; + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(function () { bowling.roll(2); }).toThrow( + new Error('Cannot roll after game is over')); + }); + + xit('cannot roll after bonus rolls for a strike', function () { + var rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 3, 2]; + var bowling = new Bowling(); + previousRolls(bowling, rolls); + expect(function () { bowling.roll(2); }).toThrow( + new Error('Cannot roll after game is over')); + }); }); }); diff --git a/exercises/bowling/example.js b/exercises/bowling/example.js index 66b204fd..ea2a29b1 100644 --- a/exercises/bowling/example.js +++ b/exercises/bowling/example.js @@ -1,68 +1,135 @@ 'use strict'; -function Bowling(rolls) { - this.rolls = rolls; -} +function Bowling() { + var maxPins = 10; + var maxFrames = 10; + var frames = []; + var frameScores = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; -Bowling.prototype.score = function () { - var initialState = { - frameNumber: 1, - rollNumber: 1, - pinsRemaining: 10, - spareLastFrame: false, - strikeLastFrame: false, - twoStrikesInARow: false, - fillBall: false, - score: 0 - }; + var currentFrame = 0; + var frameRoll = 1; + var remainingPins = maxPins; + + initializeFrame(); + + function initializeFrame() { + frameRoll = 1; + remainingPins = maxPins; + currentFrame++; + } - var finalState = this.rolls.reduce(function (state, roll) { - if (roll < 0 || roll > 10) { - throw new Error('Pins must have a value from 0 to 10'); + function incrementScore(pins) { + if (currentFrame > maxFrames) return; + frameScores[currentFrame - 1] += pins; + } + + function scoreStrike() { + frames[currentFrame - 1] = 'X'; + applyStrikeBonus(maxPins); + applySpareBonus(maxPins); + frameRoll++; + } + + function scoreFirstRoll(pins) { + remainingPins = remainingPins - pins; + applySpareBonus(pins); + applyStrikeBonus(pins); + frameRoll++; + } + + function scoreSpare(pins) { + frames[currentFrame - 1] = 'S'; + applyStrikeBonus(pins); + frameRoll++; + } + + function scoreOpenFrame(pins) { + frames[currentFrame - 1] = (maxPins - remainingPins) + pins; + applyStrikeBonus(pins); + frameRoll++; + } + + function applySpareBonus(pins) { + // pins on the first roll after a spare are counted twice (on the frame of spare) + if (frames[currentFrame - 2] === 'S' ) { + frameScores[currentFrame - 2] += pins; } + } - if (roll > state.pinsRemaining) { + function applyStrikeBonus(pins) { + // on the two rolls after a strike are counted twice (on the frame of the strike) + if (frames[currentFrame - 3] === 'X' && frames[currentFrame - 2] === 'X' && + frameRoll === 1 && currentFrame <= (maxFrames + 2)) { + frameScores[currentFrame - 3] += pins; + } + if (frames[currentFrame - 2] === 'X' && currentFrame <= (maxFrames + 1)) { + frameScores[currentFrame - 2] += pins; + } + } + + function isGameOver() { + if (currentFrame <= maxFrames) return false; + + if (frames[maxFrames - 1] !== 'X' && frames[maxFrames - 1] !== 'S') return true; + + // spare in the last frame gets no more than bonus roll + if (frames[maxFrames - 1] === 'S' && frameRoll > 1) return true; + + // bonus roll after the spare in the last frame may get a strike but then the games ends without another roll + if (frames[maxFrames - 1] === 'S' && frames[maxFrames] === 'X') return true; + + if (frames[maxFrames - 1] === 'X') { + // if the first bonus roll is not a strike then finish the bonus frame + if (frames[maxFrames] !== 'X' && currentFrame > maxFrames + 1) return true; + + if (frames[maxFrames] === 'X') { + // if the second bonus roll is a strike, but was still used, the game is over + if (frames[maxFrames + 1] !== 'X' && frameRoll > 1) return true; + // if the second bonus roll is a strike the game is over + if (frames[maxFrames + 1] === 'X') return true; + } + } + return false; + } + + this.roll = function (pins) { + if (pins < 0) { + throw new Error( 'Negative roll is invalid'); + } + + if (pins > remainingPins) { throw new Error('Pin count exceeds pins on the lane'); } - if (state.frameNumber > 10) { - throw new Error('Should not be able to roll after game is over'); + if (isGameOver()) { + throw new Error('Cannot roll after game is over'); } - var finalFrame = state.frameNumber === 10; - var strike = state.rollNumber === 1 && roll === 10; - var spare = state.rollNumber === 2 && roll === state.pinsRemaining; - var frameOver = finalFrame - ? (!state.fillBall && !spare && state.rollNumber === 2) || state.rollNumber === 3 - : strike || spare || state.rollNumber === 2; - - var score = state.score + roll; - - if (state.strikeLastFrame && state.rollNumber < 3) { score += roll; } - if (state.spareLastFrame && state.rollNumber === 1) { score += roll; } - if (state.twoStrikesInARow && state.rollNumber === 1) { score += roll; } - - var next = {}; - - next.frameNumber = frameOver ? state.frameNumber + 1 : state.frameNumber; - next.rollNumber = frameOver ? 1 : state.rollNumber + 1; - next.pinsRemaining = finalFrame - ? ((strike || spare) ? 10 : state.pinsRemaining - roll) - : (frameOver ? 10 : state.pinsRemaining - roll); - next.spareLastFrame = frameOver ? spare : state.spareLastFrame; - next.strikeLastFrame = frameOver ? strike : state.strikeLastFrame; - next.twoStrikesInARow = frameOver ? strike && state.strikeLastFrame : state.twoStrikesInARow; - next.fillBall = next.fillBall || (finalFrame && (strike || spare)); - next.score = score; - - return next; - }, initialState); - - if (finalState.frameNumber !== 11) { - throw new Error('Score cannot be taken until the end of the game'); - } + incrementScore(pins); - return finalState.score; -}; + if (frameRoll === 1) { + if (pins === maxPins) { + scoreStrike(); + initializeFrame(); + } else { + scoreFirstRoll(pins); + } + } else { + if (pins === remainingPins) { + scoreSpare(pins); + } else { + scoreOpenFrame(pins); + } + initializeFrame(); + } + }; + + this.score = function () { + if (!isGameOver()) { + throw new Error('Score cannot be taken until the end of the game'); + } + return frameScores.reduce(function (total, num) {return total + num;}); + }; +} module.exports = Bowling; diff --git a/exercises/bracket-push/README.md b/exercises/bracket-push/README.md index 0496d2f1..66c336ef 100644 --- a/exercises/bracket-push/README.md +++ b/exercises/bracket-push/README.md @@ -5,26 +5,29 @@ verify that all the pairs are matched and nested correctly. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine bracket-push.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/bracket-push/example.js b/exercises/bracket-push/example.js index ab3d22d3..ace16508 100644 --- a/exercises/bracket-push/example.js +++ b/exercises/bracket-push/example.js @@ -28,7 +28,7 @@ var bracketPush = module.exports = function (input) { for (var k = 0; k < 3; k++) { if (bracketArray[topNumber] === openArray[k]) { - if (typeof bracketArray[(topNumber + 1)] !== undefined) { + if (typeof bracketArray[(topNumber + 1)] !== 'undefined') { if (bracketArray[(topNumber + 1)] === closeArray[k]) { bracketArray.splice(topNumber, 2); return bracketPush(bracketArray); diff --git a/exercises/change/README.md b/exercises/change/README.md index 44bf1f65..282186fe 100644 --- a/exercises/change/README.md +++ b/exercises/change/README.md @@ -1,36 +1,50 @@ # Change -Correctly determine the change to be given using the least number of coins. +Correctly determine the fewest number of coins to be given to a customer such +that the sum of the coins' value would equal the correct amount of change. -The solution will need to accept a value of change to be given and an array of -coin denominations. The program returns the array of coin denominations to -produce the correct amount of change. For example, if change for 37 cents -is required from coins with the denominations of 1, 5, 10 and 25 then the -result is an array with the values: 1, 1, 10 and 25. +## For example + +- An input of 15 with [1, 5, 10, 25, 100] should return one nickel (5) + and one dime (10) or [0, 1, 1, 0, 0] +- An input of 40 with [1, 5, 10, 25, 100] should return one nickel (5) + and one dime (10) and one quarter (25) or [0, 1, 1, 1, 0] + +## Edge cases + +- Does your algorithm work for any given set of coins? +- Can you ask for negative change? +- Can you ask for a change value smaller than the smallest coin value? ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine change.spec.js +``` -In many test suites all but the first test have been skipped. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +## Source +Software Craftsmanship - Coin Change Kata [https://web.archive.org/web/20130115115225/http://craftsmanship.sv.cmu.edu:80/exercises/coin-change-kata](https://web.archive.org/web/20130115115225/http://craftsmanship.sv.cmu.edu:80/exercises/coin-change-kata) ## 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/circular-buffer/README.md b/exercises/circular-buffer/README.md index 14f497e5..85243a97 100644 --- a/exercises/circular-buffer/README.md +++ b/exercises/circular-buffer/README.md @@ -31,40 +31,50 @@ If the buffer has 7 elements then it is completely full: When the buffer is full an error will be raised, alerting the client that further writes are blocked until a slot becomes free. -The client can opt to overwrite the oldest data with a forced write. In -this case, two more elements — A & B — are added and they overwrite the -3 & 4: +When the buffer is full, the client can opt to overwrite the oldest +data with a forced write. In this case, two more elements — A & B — +are added and they overwrite the 3 & 4: [6][7][8][9][A][B][5] -Finally, if two elements are now removed then what would be returned is -not 3 & 4 but 5 & 6 because A & B overwrote the 3 & the 4 yielding the -buffer with: +3 & 4 have been replaced by A & B making 5 now the oldest data in the +buffer. Finally, if two elements are removed then what would be +returned is 5 & 6 yielding the buffer: [ ][7][8][9][A][B][ ] -## Setup +Because there is space available, if the client again uses overwrite +to store C & D then the space where 5 & 6 were stored previously will +be used not the location of 7 & 8. 7 is still the oldest element and +the buffer is once again full. + + [D][7][8][9][A][B][C] -Go through the setup instructions for JavaScript to -install the necessary dependencies: +## Setup -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine circular-buffer.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/circular-buffer/circular-buffer.spec.js b/exercises/circular-buffer/circular-buffer.spec.js index 6f42b7a8..36b73491 100644 --- a/exercises/circular-buffer/circular-buffer.spec.js +++ b/exercises/circular-buffer/circular-buffer.spec.js @@ -57,7 +57,7 @@ describe('CircularBuffer', function () { xit('writes of undefined or null don\'t occupy buffer', function () { var buffer = circularBuffer(3); buffer.write(null); - buffer.write(undefined); + buffer.write(undefined); // eslint-disable-line no-undefined [1, 2, 3].map(function (i) { buffer.write(i.toString()); }); expect(buffer.read()).toBe('1'); }); diff --git a/exercises/circular-buffer/example.js b/exercises/circular-buffer/example.js index 870611f7..e636d4a0 100644 --- a/exercises/circular-buffer/example.js +++ b/exercises/circular-buffer/example.js @@ -68,7 +68,7 @@ function CircularBuffer(capacity) { } function isEmpty(data) { - return data === null || data === undefined; + return !data; } } diff --git a/exercises/clock/README.md b/exercises/clock/README.md index 0427655d..9fdc3811 100644 --- a/exercises/clock/README.md +++ b/exercises/clock/README.md @@ -8,26 +8,29 @@ Two clocks that represent the same time should be equal to each other. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine clock.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/clock/example.js b/exercises/clock/example.js index b0260dde..dc69700a 100644 --- a/exercises/clock/example.js +++ b/exercises/clock/example.js @@ -8,15 +8,12 @@ var MILLIS_IN_AN_HOUR = MINUTES_IN_AN_HOUR * MILLIS_IN_A_MINUTE; var MILLIS_IN_A_DAY = HOURS_IN_A_DAY * MILLIS_IN_AN_HOUR; function makePositive(time, maxValue) { - time %= maxValue; - time += maxValue; - return time; + return time % maxValue + maxValue; } -function at(hours, minutes) { - minutes = minutes || 0; - hours = makePositive(hours, HOURS_IN_A_DAY); - minutes = makePositive(minutes, MINUTES_IN_A_DAY); +function at(inputHours, inputMinutes) { + var minutes = makePositive(inputMinutes || 0, MINUTES_IN_A_DAY); + var hours = makePositive(inputHours, HOURS_IN_A_DAY); var clock = {}; var value = (hours * MILLIS_IN_AN_HOUR) + (minutes * MILLIS_IN_A_MINUTE); @@ -31,13 +28,13 @@ function at(hours, minutes) { return time[0] + ':' + time[1]; }; - clock.plus = function (minutes) { - value += minutes * MILLIS_IN_A_MINUTE; + clock.plus = function (addMinutes) { + value += addMinutes * MILLIS_IN_A_MINUTE; return clock; }; - clock.minus = function (minutes) { - value -= minutes * MILLIS_IN_A_MINUTE; + clock.minus = function (subMinutes) { + value -= subMinutes * MILLIS_IN_A_MINUTE; return clock; }; diff --git a/exercises/collatz-conjecture/README.md b/exercises/collatz-conjecture/README.md index e79a5db2..f4dcfa8e 100644 --- a/exercises/collatz-conjecture/README.md +++ b/exercises/collatz-conjecture/README.md @@ -28,26 +28,29 @@ Resulting in 9 steps. So for input n = 12, the return value would be 9. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine collatz-conjecture.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/connect/README.md b/exercises/connect/README.md new file mode 100644 index 00000000..8e711f2b --- /dev/null +++ b/exercises/connect/README.md @@ -0,0 +1,60 @@ +# Connect + +Compute the result for a game of Hex / Polygon. + +The abstract boardgame known as +[Hex](https://en.wikipedia.org/wiki/Hex_%28board_game%29) / Polygon / +CON-TAC-TIX is quite simple in rules, though complex in practice. Two players +place stones on a rhombus with hexagonal fields. The player to connect his/her +stones to the opposite side first wins. The four sides of the rhombus are +divided between the two players (i.e. one player gets assigned a side and the +side directly opposite it and the other player gets assigned the two other +sides). + +Your goal is to build a program that given a simple representation of a board +computes the winner (or lack thereof). Note that all games need not be "fair". +(For example, players may have mismatched piece counts.) + +The boards look like this (with spaces added for readability, which won't be in +the representation passed to your code): + +```text +. O . X . + . X X O . + O O O X . + . X O X O + X O O O X +``` + +"Player `O`" plays from top to bottom, "Player `X`" plays from left to right. In +the above example `O` has made a connection from left to right but nobody has +won since `O` didn't connect top and bottom. + +## Setup + +Go through the setup instructions for JavaScript to install the + necessary dependencies: + +http://exercism.io/languages/javascript/installation + +## Running the test suite + +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: + +```sh +npm install -g jasmine +``` + +Run the test suite from the exercise directory with: + +```sh +jasmine connect.spec.js +``` + +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. + +## 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/connect/connect.spec.js b/exercises/connect/connect.spec.js new file mode 100644 index 00000000..1b926346 --- /dev/null +++ b/exercises/connect/connect.spec.js @@ -0,0 +1,108 @@ +var Board = require('./connect'); + +describe('Judging a game of connect', function () { + it('an empty board has no winner', function () { + var board = [ + '. . . . .', + ' . . . . .', + ' . . . . .', + ' . . . . .', + ' . . . . .' + ]; + expect(new Board(board).winner()).toEqual(''); + }); + + xit('X can win on a 1x1 board', function () { + var board = [ + 'X' + ]; + expect(new Board(board).winner()).toEqual('X'); + }); + + xit('O can win on a 1x1 board', function () { + var board = [ + 'O' + ]; + expect(new Board(board).winner()).toEqual('O'); + }); + + xit('only edges does not make a winner', function () { + var board = [ + 'O O O X', + ' X . . X', + ' X . . X', + ' X O O O' + ]; + expect(new Board(board).winner()).toEqual(''); + }); + + xit('illegal diagonal does not make a winner', function () { + var board = [ + 'X O . .', + ' O X X X', + ' O X O .', + ' . O X .', + ' X X O O' + ]; + expect(new Board(board).winner()).toEqual(''); + }); + + xit('nobody wins crossing adjacent angles', function () { + var board = [ + 'X . . .', + ' . X O .', + ' O . X O', + ' . O . X', + ' . . O .' + ]; + expect(new Board(board).winner()).toEqual(''); + }); + + xit('X wins crossing from left to right', function () { + var board = [ + '. O . .', + ' O X X X', + ' O X O .', + ' X X O X', + ' . O X .' + ]; + expect(new Board(board).winner()).toEqual('X'); + }); + + xit('O wins crossing from top to bottom', function () { + var board = [ + '. O . .', + ' O X X X', + ' O O O .', + ' X X O X', + ' . O X .' + ]; + expect(new Board(board).winner()).toEqual('O'); + }); + + xit('X wins using a convoluted path', function () { + var board = [ + '. X X . .', + ' X . X . X', + ' . X . X .', + ' . X X . .', + ' O O O O O' + ]; + expect(new Board(board).winner()).toEqual('X'); + }); + + xit('X wins using a spiral path', function () { + var board = [ + 'O X X X X X X X X', + ' O X O O O O O O O', + ' O X O X X X X X O', + ' O X O X O O O X O', + ' O X O X X X O X O', + ' O X O O O X O X O', + ' O X X X X X O X O', + ' O O O O O O O X O', + ' X X X X X X X X O' + ]; + expect(new Board(board).winner()).toEqual('X'); + }); +}); diff --git a/exercises/connect/example.js b/exercises/connect/example.js new file mode 100644 index 00000000..9c709a1b --- /dev/null +++ b/exercises/connect/example.js @@ -0,0 +1,105 @@ +/** + * "Player O" plays from top to bottom, "Player X" plays from left to right. + * @param {string[]} initBoard - The starting state of the board + * @returns {Object} - The board business object + */ +var Board = function (initBoard) { + this.board = initBoard.slice(); +}; + +Board.prototype.winner = function () { + var players = ['X', 'O']; + for (var i = 0; i < players.length; i++) { + if (this.checkWin(players[i])) { + return players[i]; + } + } + return ''; +}; + +Board.prototype.checkWin = function (player) { + var positions = this.startPositions(player); + for (var i = 0; i < positions.length; i++) { + if (this.search(positions[i], player, [])) { + return true; + } + } + return false; +}; + +Board.prototype.search = function (pos, XorO, isChecked) { + var self = this; + if (!this.containsPiece(pos, XorO)) { + return false; + } + if (this.winningSpot(pos, XorO)) { + return true; + } + var checked = isChecked.slice(0); + checked.push(pos); + + var matches = this.neighbors(pos) + .filter(function (cell) { + return self.containsPiece(cell, XorO) && + checked.filter( + function (spot) { + return locationMatch(spot, cell); + } + ).length === 0; + }); + + function locationMatch(spot, cell) { + return spot.x === cell.x && spot.y === cell.y; + } + + if (matches.length === 0) { + return false; + } + + return matches + .filter( + function (spot) { + return self.search(spot, XorO, checked); + } + ).length > 0; +}; + +Board.prototype.neighbors = function (cell) { + return [ + {x: cell.x, y: cell.y + 2}, + {x: cell.x, y: cell.y - 2}, + + {x: cell.x + 1, y: cell.y + 1}, + {x: cell.x - 1, y: cell.y + 1}, + + {x: cell.x + 1, y: cell.y - 1}, + {x: cell.x - 1, y: cell.y - 1} + ]; +}; + +Board.prototype.startPositions = function (XorO) { + var self = this; + return XorO === 'X' ? + this.board + .map(function (pos, i) { + return {x: i, y: i}; + }) : + Array.prototype + .map + .call(self.board[0], function (pos, i) { + return {x: 0, y: i}; + }); +}; + +Board.prototype.winningSpot = function (cell, XorO) { + return XorO === 'X' ? + cell.y === this.board[0].length - 1 + cell.x : + cell.x === this.board.length - 1; +}; + +Board.prototype.containsPiece = function (cell, XorO) { + return this.board[cell.x] && this.board[cell.x][cell.y] === XorO; +}; + + +module.exports = Board; diff --git a/exercises/crypto-square/README.md b/exercises/crypto-square/README.md index 515f68f2..9fbbe98f 100644 --- a/exercises/crypto-square/README.md +++ b/exercises/crypto-square/README.md @@ -26,7 +26,7 @@ and `r` is the number of rows. Our normalized text is 54 characters long, dictating a rectangle with `c = 8` and `r = 7`: -```plain +```text ifmanwas meanttos tayonthe @@ -41,22 +41,24 @@ right. The message above is coded as: -```plain +```text imtgdvsfearwermayoogoanouuiontnnlvtwttddesaohghnsseoau ``` -Output the encoded text in chunks. Phrases that fill perfect squares -`(r X r)` should be output in `r`-length chunks separated by spaces. -Imperfect squares will have `n` empty spaces. Those spaces should be distributed evenly across the last `n` rows. +Output the encoded text in chunks. Phrases that fill perfect rectangles +`(r X c)` should be output `c` chunks of `r` length, separated by spaces. +Phrases that do not fill perfect rectangles will have `n` empty spaces. +Those spaces should be distributed evenly, added to the end of the last +`n` chunks. -```plain -imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau +```text +imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau ``` Notice that were we to stack these, we could visually decode the cyphertext back in to the original message: -```plain +```text imtgdvs fearwer mayoogo @@ -69,26 +71,29 @@ sseoau ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js - -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine crypto-square.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/crypto-square/example.js b/exercises/crypto-square/example.js index 173f2bff..44589d5b 100644 --- a/exercises/crypto-square/example.js +++ b/exercises/crypto-square/example.js @@ -22,7 +22,8 @@ module.exports = function (input) { this.ciphertext = function () { var textSegments = this.plaintextSegments(); - var i, j; + var i; + var j; var columns = []; var currentSegment; var currentLetter; diff --git a/exercises/custom-set/README.md b/exercises/custom-set/README.md index 765ce0be..9635f1e0 100644 --- a/exercises/custom-set/README.md +++ b/exercises/custom-set/README.md @@ -9,27 +9,29 @@ unique elements. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.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`. +```sh +jasmine custom-set.spec.js +``` +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## 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/custom-set/example-gen.js b/exercises/custom-set/example-gen.js index c791c799..f27732f6 100644 --- a/exercises/custom-set/example-gen.js +++ b/exercises/custom-set/example-gen.js @@ -160,7 +160,7 @@ function renderSuite(tests, otherTests, suiteTemplate) { return suiteTemplate(tests.concat(otherTests)); } -function suiteTemplate(tests) { +function suiteTemplateFn(tests) { return ( `var CustomSet = require('./custom-set'); @@ -179,8 +179,8 @@ function testTemplate(isEnabled, description, body) { `); } -function array(array) { - return array.length === 0 ? '' : `[${array.join(', ')}]`; +function array(arr) { + return arr.length === 0 ? '' : `[${arr.join(', ')}]`; } function generate() { @@ -193,7 +193,7 @@ function generate() { suiteData: suiteData, testBodyTemplates: TEST_BODY_TEMPLATES, extraTests: NON_CANONICAL_TESTS, - suiteTemplate: suiteTemplate + suiteTemplate: suiteTemplateFn })); } diff --git a/exercises/diamond/README.md b/exercises/diamond/README.md index 6dab43a6..7ba94abd 100644 --- a/exercises/diamond/README.md +++ b/exercises/diamond/README.md @@ -1,7 +1,7 @@ # Diamond -The diamond kata takes as its input a letter, and outputs it in a diamond -shape. Given a letter, it prints a diamond starting with 'A', with the +The diamond kata takes as its input a letter, and outputs it in a diamond +shape. Given a letter, it prints a diamond starting with 'A', with the supplied letter at the widest point. ## Requirements @@ -15,7 +15,7 @@ supplied letter at the widest point. * The diamond has a square shape (width equals height). * The letters form a diamond shape. * The top half has the letters in ascending order. -* The bottom half has the letters in descending order. +* The bottom half has the letters in descending order. * The four corners (containing the spaces) are triangles. ## Examples @@ -24,13 +24,13 @@ In the following examples, spaces are indicated by `·` characters. Diamond for letter 'A': -```plain +```text A ``` Diamond for letter 'C': -```plain +```text ··A·· ·B·B· C···C @@ -40,7 +40,7 @@ C···C Diamond for letter 'E': -```plain +```text ····A···· ···B·B··· ··C···C·· @@ -54,26 +54,29 @@ E·······E ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js - -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine diamond.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/diamond/diamond.spec.js b/exercises/diamond/diamond.spec.js index 84ed61fc..5e52b952 100644 --- a/exercises/diamond/diamond.spec.js +++ b/exercises/diamond/diamond.spec.js @@ -4,12 +4,12 @@ describe('Diamond', function () { var diamond = new Diamond(); it('test letter A', function () { - result = 'A\n'; + var result = 'A\n'; expect(diamond.makeDiamond('A')).toEqual(result); }); it('test letter C', function () { - result = [' A ', + var result = [' A ', ' B B ', 'C C', ' B B ', @@ -18,7 +18,7 @@ describe('Diamond', function () { }); it('test letter E', function () { - result = [' A ', + var result = [' A ', ' B B ', ' C C ', ' D D ', diff --git a/exercises/diamond/example.js b/exercises/diamond/example.js index e7ffdf45..d535e64e 100644 --- a/exercises/diamond/example.js +++ b/exercises/diamond/example.js @@ -5,8 +5,8 @@ var Diamond = function () { for (var i = 0; i <= inputIndex; i++) { output += getLine(inputIndex, i); } - for (var i = inputIndex - 1; i >= 0; i--) { - output += getLine(inputIndex, i); + for (var j = inputIndex - 1; j >= 0; j--) { + output += getLine(inputIndex, j); } return output; }; diff --git a/exercises/difference-of-squares/README.md b/exercises/difference-of-squares/README.md index e4320442..5c181acf 100644 --- a/exercises/difference-of-squares/README.md +++ b/exercises/difference-of-squares/README.md @@ -1,4 +1,4 @@ -# Difference of Squares +# Difference Of Squares Find the difference between the square of the sum and the sum of the squares of the first N natural numbers. @@ -14,26 +14,29 @@ natural numbers is 3025 - 385 = 2640. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine difference-of-squares.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/diffie-hellman/README.md b/exercises/diffie-hellman/README.md index 2a8453fb..f04f3c27 100644 --- a/exercises/diffie-hellman/README.md +++ b/exercises/diffie-hellman/README.md @@ -39,31 +39,29 @@ secret s. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Requirements +## Running the test suite +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: +```sh +npm install -g jasmine +``` -## Making the test suite pass +Run the test suite from the exercise directory with: -Execute the tests with: - - jasmine .spec.js - -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: - - jasmine hello-world.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`. +```sh +jasmine diffie-hellman.spec.js +``` +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/diffie-hellman/diffie-hellman.spec.js b/exercises/diffie-hellman/diffie-hellman.spec.js index 5f7faa65..47b4faae 100644 --- a/exercises/diffie-hellman/diffie-hellman.spec.js +++ b/exercises/diffie-hellman/diffie-hellman.spec.js @@ -1,6 +1,6 @@ var DiffieHellman = require('./diffie-hellman'); -describe('diffie-hellman', function(){ +describe('diffie-hellman', function () { var p = 23; var g = 5; var diffieHellman = new DiffieHellman(p, g); @@ -11,57 +11,57 @@ describe('diffie-hellman', function(){ var bobPrivateKey = 15; var bobPublicKey = 19; - it('throws an error if the constructor arguments are out of range', function() { - expect(function() { - new DiffieHellman(0, 9999); + it('throws an error if the constructor arguments are out of range', function () { + expect(function () { + return new DiffieHellman(0, 9999); }).toThrow(); }); - xit('throws an error if the constructor arguments are not prime', function() { - expect(function() { - new DiffieHellman(10, 13); + xit('throws an error if the constructor arguments are not prime', function () { + expect(function () { + return new DiffieHellman(10, 13); }).toThrow(); }); - xit('throws an error if private key is negative', function() { - expect(function() { + xit('throws an error if private key is negative', function () { + expect(function () { diffieHellman.getPublicKeyFromPrivateKey(-1); }).toThrow(); }); - xit('throws an error if private key is zero', function() { - expect(function() { + xit('throws an error if private key is zero', function () { + expect(function () { diffieHellman.getPublicKeyFromPrivateKey(0); }).toThrow(); }); - xit('throws an error if private key is one', function() { - expect(function() { + xit('throws an error if private key is one', function () { + expect(function () { diffieHellman.getPublicKeyFromPrivateKey(1); }).toThrow(); }); - xit('throws an error if private key equals the modulus parameter p', function() { - expect(function() { + xit('throws an error if private key equals the modulus parameter p', function () { + expect(function () { diffieHellman.getPublicKeyFromPrivateKey(p); }).toThrow(); }); - xit('throws an error if private key is greater than the modulus parameter p', function() { - expect(function() { + xit('throws an error if private key is greater than the modulus parameter p', function () { + expect(function () { diffieHellman.getPublicKeyFromPrivateKey(p + 1); }).toThrow(); }); - xit('when given a private key, returns the correct public one', function() { + xit('when given a private key, returns the correct public one', function () { expect(diffieHellman.getPublicKeyFromPrivateKey(alicePrivateKey)).toEqual(alicePublicKey); }); - xit('when given a different private key, returns the correct public one', function() { + xit('when given a different private key, returns the correct public one', function () { expect(diffieHellman.getPublicKeyFromPrivateKey(bobPrivateKey)).toEqual(bobPublicKey); }); - xit('can generate a shared secret from our private key and their public key', function() { + xit('can generate a shared secret from our private key and their public key', function () { var sharedSecret = 2; expect(diffieHellman.getSharedSecret(alicePrivateKey, bobPublicKey)) diff --git a/exercises/diffie-hellman/example.js b/exercises/diffie-hellman/example.js index bbdfe16d..ce6c9141 100644 --- a/exercises/diffie-hellman/example.js +++ b/exercises/diffie-hellman/example.js @@ -1,10 +1,10 @@ -var DiffieHellman = function(p, g){ +var DiffieHellman = function (p, g) { this.p = p; this.g = g; // array of first 1000 primes. - this.PRIMES= [ + this.PRIMES = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919 ]; @@ -19,14 +19,14 @@ var DiffieHellman = function(p, g){ return Math.pow(theirPublicKey, ourPrivateKey) % this.p; }; - this.validateInitialArguments = function (p, g){ + this.validateInitialArguments = function (primeModulus, generator) { var BIGGEST_PRIME = this.PRIMES[this.PRIMES.length - 1]; - return p >= 2 - && g >= 2 - && p <= BIGGEST_PRIME - && g <= BIGGEST_PRIME - && arrIncludes(this.PRIMES, p) - && arrIncludes(this.PRIMES, g); + return primeModulus >= 2 + && generator >= 2 + && primeModulus <= BIGGEST_PRIME + && generator <= BIGGEST_PRIME + && arrIncludes(this.PRIMES, primeModulus) + && arrIncludes(this.PRIMES, generator); }; function arrIncludes(arr, a) { @@ -40,7 +40,7 @@ var DiffieHellman = function(p, g){ if (!this.validateInitialArguments(p, g)) { - throw Error('Constructor arguments are out of range or non-prime!'); + throw Error('Constructor arguments are out of range or non-prime!'); } }; diff --git a/exercises/etl/README.md b/exercises/etl/README.md index 3cbb4ed5..fad82d79 100644 --- a/exercises/etl/README.md +++ b/exercises/etl/README.md @@ -1,8 +1,9 @@ -# Etl +# ETL We are going to do the `Transform` step of an Extract-Transform-Load. ### ETL + Extract-Transform-Load (ETL) is a fancy way of saying, "We have some crufty, legacy data over in this system, and now we need it in this shiny new system over here, so we're going to migrate this." @@ -11,6 +12,7 @@ once." That's then typically followed by much forehead slapping and moaning about how stupid we could possibly be.) ### The goal + We're going to extract some scrabble scores from a legacy system. The old system stored a list of letters per score: @@ -46,26 +48,29 @@ game while being scored at 4 in the Hawaiian-language version. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine etl.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/flatten-array/README.md b/exercises/flatten-array/README.md index bdb7ff67..2a98a300 100644 --- a/exercises/flatten-array/README.md +++ b/exercises/flatten-array/README.md @@ -3,36 +3,38 @@ Take a nested list and return a single flattened list with all values except nil/null. The challenge is to write a function that accepts an arbitrarily-deep nested list-like structure and returns a flattened structure without any nil/null values. - + For Example input: [1,[2,3,null,4],[null],5] output: [1,2,3,4,5] - ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine flatten-array.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/flatten-array/example.js b/exercises/flatten-array/example.js index 63ab232b..658eb26e 100644 --- a/exercises/flatten-array/example.js +++ b/exercises/flatten-array/example.js @@ -1,11 +1,12 @@ -var Flattener = function () {}; +var Flattener = function () { }; -Flattener.prototype.flatten = function (unflattenedArray, flattenedArray) { - var self = this, flattenedArray = flattenedArray || []; +Flattener.prototype.flatten = function (unflattenedArray, inputFlattenedArray) { + var self = this; + var flattenedArray = inputFlattenedArray || []; unflattenedArray.forEach(function (element) { if (Array.isArray(element)) { - return self.flatten(element, flattenedArray); - } else if ( element !== null) { + self.flatten(element, flattenedArray); + } else if (element !== null) { flattenedArray.push(element); } }); diff --git a/exercises/flatten-array/flatten-array.spec.js b/exercises/flatten-array/flatten-array.spec.js index 6080fe07..4c5be05f 100644 --- a/exercises/flatten-array/flatten-array.spec.js +++ b/exercises/flatten-array/flatten-array.spec.js @@ -3,24 +3,24 @@ var Flattener = require('./flatten-array.js'); describe('FlattenArray', function () { var flattener = new Flattener(); it('flattens a nested list', function () { - expect(flattener.flatten([[]])).toEqual([]); - }); + expect(flattener.flatten([[]])).toEqual([]); + }); xit('flattens a 2 level nested list', function () { - expect(flattener.flatten([1, [2, 3, 4], 5])).toEqual([1, 2, 3, 4, 5]); - }); + expect(flattener.flatten([1, [2, 3, 4], 5])).toEqual([1, 2, 3, 4, 5]); + }); xit('flattens a 3 level nested list', function () { - expect(flattener.flatten([1, [2, 3, 4], 5, [6, [7, 8]]])).toEqual([1, 2, 3, 4, 5, 6, 7, 8]); - }); - xit('flattens a 5 level nested list', function () { - expect(flattener.flatten([0, 2, [[2, 3], 8, 100, 4, [[[50]]]], -2])).toEqual([0, 2, 2, 3, 8, 100, 4, 50, -2]); - }); + expect(flattener.flatten([1, [2, 3, 4], 5, [6, [7, 8]]])).toEqual([1, 2, 3, 4, 5, 6, 7, 8]); + }); + xit('flattens a 5 level nested list', function () { + expect(flattener.flatten([0, 2, [[2, 3], 8, 100, 4, [[[50]]]], -2])).toEqual([0, 2, 2, 3, 8, 100, 4, 50, -2]); + }); xit('flattens a 6 level nest list', function () { - expect(flattener.flatten([1, [2, [[3]], [4, [[5]]], 6, 7], 8])).toEqual([1, 2, 3, 4, 5, 6, 7, 8]); - }); + expect(flattener.flatten([1, [2, [[3]], [4, [[5]]], 6, 7], 8])).toEqual([1, 2, 3, 4, 5, 6, 7, 8]); + }); xit('flattens a 6 level nest list with null values', function () { - expect(flattener.flatten([0, 2, [[2, 3], 8, [[100]], null, [[null]]], -2])).toEqual([0, 2, 2, 3, 8, 100, -2]); - }); + expect(flattener.flatten([0, 2, [[2, 3], 8, [[100]], null, [[null]]], -2])).toEqual([0, 2, 2, 3, 8, 100, -2]); + }); xit('returns an empty list if all values in nested list are null', function () { - expect(flattener.flatten([null, [[[null]]], null, null, [[null, null], null], null])).toEqual([]); - }); + expect(flattener.flatten([null, [[[null]]], null, null, [[null, null], null], null])).toEqual([]); + }); }); diff --git a/exercises/food-chain/README.md b/exercises/food-chain/README.md index 9386f059..1f1cf16a 100644 --- a/exercises/food-chain/README.md +++ b/exercises/food-chain/README.md @@ -10,7 +10,7 @@ This is a [cumulative song](http://en.wikipedia.org/wiki/Cumulative_song) of unk This is one of many common variants. -```plain +```text I know an old lady who swallowed a fly. I don't know why she swallowed the fly. Perhaps she'll die. @@ -65,26 +65,29 @@ She's dead, of course! ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js - -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine food-chain.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/food-chain/example.js b/exercises/food-chain/example.js index 032bbd63..f3b567b2 100644 --- a/exercises/food-chain/example.js +++ b/exercises/food-chain/example.js @@ -29,51 +29,64 @@ FoodChain.prototype.verses = function (first, last) { /** * Return song verse by number. * - * @param {Number} verse + * @param {Number} number * verse number * * @return {String} * song verse */ FoodChain.prototype.verse = function (number) { + var verse; + switch (number) { - case 1: return '' + - 'I know an old lady who swallowed a fly.\n' + 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; - - case 2: return '' + - 'I know an old lady who swallowed a spider.\n' + 'It wriggled and jiggled and tickled inside her.\n' + - 'She swallowed the spider to catch the fly.\n' + 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; - - case 3: return '' + - 'I know an old lady who swallowed a bird.\n' + 'How absurd to swallow a bird!\n' + - 'She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n' + - 'She swallowed the spider to catch the fly.\n' + 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; - - case 4: return '' + - 'I know an old lady who swallowed a cat.\n' + 'Imagine that, to swallow a cat!\n' + 'She swallowed the cat to catch the bird.\n' + - 'She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n' + 'She swallowed the spider to catch the fly.\n' + - 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; - - case 5: return '' + - 'I know an old lady who swallowed a dog.\n' + 'What a hog, to swallow a dog!\n' + 'She swallowed the dog to catch the cat.\n' + - 'She swallowed the cat to catch the bird.\n' + 'She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n' + - 'She swallowed the spider to catch the fly.\n' + 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; - - case 6: return '' + - 'I know an old lady who swallowed a goat.\n' + 'Just opened her throat and swallowed a goat!\n' + 'She swallowed the goat to catch the dog.\n' + - 'She swallowed the dog to catch the cat.\n' + 'She swallowed the cat to catch the bird.\n' + - 'She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n' + - 'She swallowed the spider to catch the fly.\n' + 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; - - case 7: return '' + - 'I know an old lady who swallowed a cow.\n' + 'I don\'t know how she swallowed a cow!\n' + 'She swallowed the cow to catch the goat.\n' + - 'She swallowed the goat to catch the dog.\n' + 'She swallowed the dog to catch the cat.\n' + 'She swallowed the cat to catch the bird.\n' + - 'She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n' + 'She swallowed the spider to catch the fly.\n' + - 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; - - case 8: return '' + - 'I know an old lady who swallowed a horse.\n' + 'She\'s dead, of course!\n'; + case 1: + verse = 'I know an old lady who swallowed a fly.\n' + 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; + break; + + case 2: + verse = 'I know an old lady who swallowed a spider.\n' + 'It wriggled and jiggled and tickled inside her.\n' + + 'She swallowed the spider to catch the fly.\n' + 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; + break; + + case 3: + verse = 'I know an old lady who swallowed a bird.\n' + 'How absurd to swallow a bird!\n' + + 'She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n' + + 'She swallowed the spider to catch the fly.\n' + 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; + break; + + case 4: + verse = 'I know an old lady who swallowed a cat.\n' + 'Imagine that, to swallow a cat!\n' + 'She swallowed the cat to catch the bird.\n' + + 'She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n' + 'She swallowed the spider to catch the fly.\n' + + 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; + break; + + case 5: + verse = 'I know an old lady who swallowed a dog.\n' + 'What a hog, to swallow a dog!\n' + 'She swallowed the dog to catch the cat.\n' + + 'She swallowed the cat to catch the bird.\n' + 'She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n' + + 'She swallowed the spider to catch the fly.\n' + 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; + break; + + case 6: + verse = 'I know an old lady who swallowed a goat.\n' + 'Just opened her throat and swallowed a goat!\n' + 'She swallowed the goat to catch the dog.\n' + + 'She swallowed the dog to catch the cat.\n' + 'She swallowed the cat to catch the bird.\n' + + 'She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n' + + 'She swallowed the spider to catch the fly.\n' + 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; + break; + + case 7: + verse = 'I know an old lady who swallowed a cow.\n' + 'I don\'t know how she swallowed a cow!\n' + 'She swallowed the cow to catch the goat.\n' + + 'She swallowed the goat to catch the dog.\n' + 'She swallowed the dog to catch the cat.\n' + 'She swallowed the cat to catch the bird.\n' + + 'She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n' + 'She swallowed the spider to catch the fly.\n' + + 'I don\'t know why she swallowed the fly. Perhaps she\'ll die.\n'; + break; + + case 8: verse = 'I know an old lady who swallowed a horse.\n' + 'She\'s dead, of course!\n'; + break; + + default: verse = ''; } + + return verse; }; FoodChain.prototype.sing = FoodChain.prototype.verses.bind(null, 1, 8); diff --git a/exercises/forth/README.md b/exercises/forth/README.md new file mode 100644 index 00000000..2c42e805 --- /dev/null +++ b/exercises/forth/README.md @@ -0,0 +1,55 @@ +# Forth + +Implement an evaluator for a very simple subset of Forth. + +[Forth](https://en.wikipedia.org/wiki/Forth_%28programming_language%29) +is a stack-based programming language. Implement a very basic evaluator +for a small subset of Forth. + +Your evaluator has to support the following words: + +- `+`, `-`, `*`, `/` (integer arithmetic) +- `DUP`, `DROP`, `SWAP`, `OVER` (stack manipulation) + +Your evaluator also has to support defining new words using the +customary syntax: `: word-name definition ;`. + +To keep things simple the only data type you need to support is signed +integers of at least 16 bits size. + +You should use the following rules for the syntax: a number is a +sequence of one or more (ASCII) digits, a word is a sequence of one or +more letters, digits, symbols or punctuation that is not a number. +(Forth probably uses slightly different rules, but this is close +enough.) + +Words are case-insensitive. + +## Setup + +Go through the setup instructions for JavaScript to install the + necessary dependencies: + +http://exercism.io/languages/javascript/installation + +## Running the test suite + +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: + +```sh +npm install -g jasmine +``` + +Run the test suite from the exercise directory with: + +```sh +jasmine forth.spec.js +``` + +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. + +## 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/forth/example.js b/exercises/forth/example.js new file mode 100644 index 00000000..e1bfa34b --- /dev/null +++ b/exercises/forth/example.js @@ -0,0 +1,66 @@ +var Forth = function () { + this.stack = []; + this.commands = Forth.basicCommands(); +}; + +Forth.prototype.evaluate = function (program) { + var words = program.toLowerCase().split(' '); + + for (var t = 0; t < words.length; t++) { + var word = words[t]; + + if (/^-?\d+$/.test(word)) { + // numbers + this.stack.push(Number(word)); + } else if (word === ':') { + // word definition + var semicolon = words.indexOf(';', t); + if (semicolon === -1) throw new Error('Unterminated definition'); + this.defineCommand(words[t + 1], words.slice(t + 2, semicolon).join(' ')); + t = semicolon; + } else { + // commands + var command = this.commands[word]; + if (!command) throw new Error('Unknown command'); + this.performCommand(command); + } + } +}; + +Forth.prototype.defineCommand = function (word, subprogram) { + if (Forth.isKeyword(word)) throw new Error('Invalid definition'); + this.commands[word] = { + arity: 0, // handled inside the call + execute: this.evaluate.bind(this, subprogram) + }; +}; + +Forth.prototype.performCommand = function (command) { + if (command.arity > this.stack.length) throw new Error('Stack empty'); + + var args = this.stack.splice(this.stack.length - command.arity); + var vals = command.execute.apply(this, args); + this.stack.push.apply(this.stack, vals); +}; + +Forth.isKeyword = function (word) { + return word === ':' || word === ';' || /^-?\d+$/.test(word); +}; + +Forth.basicCommands = function () { + return { + '+': { arity: 2, execute: function (a, b) { return [a + b]; } }, + '-': { arity: 2, execute: function (a, b) { return [a - b]; } }, + '*': { arity: 2, execute: function (a, b) { return [a * b]; } }, + '/': { arity: 2, execute: function (a, b) { + if (b === 0) throw new Error('Division by zero'); + return [Math.floor(a / b)]; + } }, + dup: { arity: 1, execute: function (a) { return [a, a]; } }, + drop: { arity: 1, execute: function () {} }, + swap: { arity: 2, execute: function (a, b) { return [b, a]; } }, + over: { arity: 2, execute: function (a, b) { return [a, b, a]; } } + }; +}; + +module.exports = Forth; diff --git a/exercises/forth/forth.spec.js b/exercises/forth/forth.spec.js new file mode 100644 index 00000000..43bcd72a --- /dev/null +++ b/exercises/forth/forth.spec.js @@ -0,0 +1,259 @@ +var Forth = require('./forth'); + +describe('Forth', function () { + var forth; + + beforeEach(function () { + forth = new Forth(); + }); + + describe('parsing and numbers', function () { + it('just pushes numbers onto the stack', function () { + forth.evaluate('1 2 3 4 5'); + expect(forth.stack).toEqual([1, 2, 3, 4, 5]); + }); + xit('pushes negative numbers onto the stack', function () { + forth.evaluate('-1 -2 -3 -4 -5'); + expect(forth.stack).toEqual([-1, -2, -3, -4, -5]); + }); + }); + + describe('addition', function () { + xit('can add two numbers', function () { + forth.evaluate('1 2 +'); + expect(forth.stack).toEqual([3]); + }); + xit('errors if there is only one value on the stack', function () { + expect(function () { + forth.evaluate('1 +'); + }).toThrow(new Error('Stack empty')); + }); + xit('errors if there is nothing on the stack', function () { + expect(function () { + forth.evaluate('+'); + }).toThrow(new Error('Stack empty')); + }); + }); + + describe('subtraction', function () { + xit('can subtract two numbers', function () { + forth.evaluate('3 4 -'); + expect(forth.stack).toEqual([-1]); + }); + xit('errors if there is only one value on the stack', function () { + expect(function () { + forth.evaluate('1 -'); + }).toThrow(new Error('Stack empty')); + }); + xit('errors if there is nothing on the stack', function () { + expect(function () { + forth.evaluate('-'); + }).toThrow(new Error('Stack empty')); + }); + }); + + describe('multiplication', function () { + xit('can multiply two numbers', function () { + forth.evaluate('2 4 *'); + expect(forth.stack).toEqual([8]); + }); + xit('errors if there is only one value on the stack', function () { + expect(function () { + forth.evaluate('1 *'); + }).toThrow(new Error('Stack empty')); + }); + xit('errors if there is nothing on the stack', function () { + expect(function () { + forth.evaluate('*'); + }).toThrow(new Error('Stack empty')); + }); + }); + + describe('division', function () { + xit('can divide two numbers', function () { + forth.evaluate('12 3 /'); + expect(forth.stack).toEqual([4]); + }); + xit('performs integer division', function () { + forth.evaluate('8 3 /'); + expect(forth.stack).toEqual([2]); + }); + xit('errors if dividing by zero', function () { + expect(function () { + forth.evaluate('4 0 /'); + }).toThrow(new Error('Division by zero')); + }); + xit('errors if there is only one value on the stack', function () { + expect(function () { + forth.evaluate('1 /'); + }).toThrow(new Error('Stack empty')); + }); + xit('errors if there is nothing on the stack', function () { + expect(function () { + forth.evaluate('/'); + }).toThrow(new Error('Stack empty')); + }); + }); + + describe('combined arithmetic', function () { + xit('performs addition and subtraction', function () { + forth.evaluate('1 2 + 4 -'); + expect(forth.stack).toEqual([-1]); + }); + xit('performs multiplication and division', function () { + forth.evaluate('2 4 * 3 /'); + expect(forth.stack).toEqual([2]); + }); + }); + + describe('dup', function () { + xit('copies a value on the stack', function () { + forth.evaluate('1 dup'); + expect(forth.stack).toEqual([1, 1]); + }); + xit('copies the top value on the stack', function () { + forth.evaluate('1 2 dup'); + expect(forth.stack).toEqual([1, 2, 2]); + }); + xit('errors if there is nothing on the stack', function () { + expect(function () { + forth.evaluate('dup'); + }).toThrow(new Error('Stack empty')); + }); + }); + + describe('drop', function () { + xit('removes the top value on the stack if it is the only one', function () { + forth.evaluate('1 drop'); + expect(forth.stack).toEqual([]); + }); + xit('removes the top value on the stack if it is not the only one', function () { + forth.evaluate('1 2 drop'); + expect(forth.stack).toEqual([1]); + }); + xit('errors if there is nothing on the stack', function () { + expect(function () { + forth.evaluate('drop'); + }).toThrow(new Error('Stack empty')); + }); + }); + + describe('swap', function () { + xit('swaps the top two values on the stack if they are the only ones', function () { + forth.evaluate('1 2 swap'); + expect(forth.stack).toEqual([2, 1]); + }); + xit('swaps the top two values on the stack if they are not the only ones', function () { + forth.evaluate('1 2 3 swap'); + expect(forth.stack).toEqual([1, 3, 2]); + }); + xit('errors if there is only one value on the stack', function () { + expect(function () { + forth.evaluate('1 swap'); + }).toThrow(new Error('Stack empty')); + }); + xit('errors if there is nothing on the stack', function () { + expect(function () { + forth.evaluate('swap'); + }).toThrow(new Error('Stack empty')); + }); + }); + + describe('over', function () { + xit('copies the second element if there are only two', function () { + forth.evaluate('1 2 over'); + expect(forth.stack).toEqual([1, 2, 1]); + }); + xit('copies the second element if there are more than two', function () { + forth.evaluate('1 2 3 over'); + expect(forth.stack).toEqual([1, 2, 3, 2]); + }); + xit('errors if there is only one value on the stack', function () { + expect(function () { + forth.evaluate('1 over'); + }).toThrow(new Error('Stack empty')); + }); + xit('errors if there is nothing on the stack', function () { + expect(function () { + forth.evaluate('over'); + }).toThrow(new Error('Stack empty')); + }); + }); + + describe('user-defined words', function () { + xit('can consist of built-in words', function () { + forth.evaluate(': dup-twice dup dup ;'); + forth.evaluate('1 dup-twice'); + expect(forth.stack).toEqual([1, 1, 1]); + }); + xit('execute in the right order', function () { + forth.evaluate(': countup 1 2 3 ;'); + forth.evaluate('countup'); + expect(forth.stack).toEqual([1, 2, 3]); + }); + xit('can override other user-defined words', function () { + forth.evaluate(': foo dup ;'); + forth.evaluate(': foo dup dup ;'); + forth.evaluate( '1 foo'); + expect(forth.stack).toEqual([1, 1, 1]); + }); + xit('can override built-in words', function () { + forth.evaluate(': swap dup ;'); + forth.evaluate('1 swap'); + expect(forth.stack).toEqual([1, 1]); + }); + xit('can override built-in operators', function () { + forth.evaluate(': + * ;'); + forth.evaluate('3 4 +'); + expect(forth.stack).toEqual([12]); + }); + xit('cannot redefine numbers', function () { + expect(function () { + forth.evaluate(': 1 2 ;'); + }).toThrow(new Error('Invalid definition')); + }); + xit('errors if executing a non-existent word', function () { + expect(function () { + forth.evaluate('foo'); + }).toThrow(new Error('Unknown command')); + }); + xit('only defines words for current instance', function () { + var first = new Forth(); + var second = new Forth(); + first.evaluate(': + - ;'); + first.evaluate('1 1 +'); + second.evaluate('1 1 +'); + expect(first.stack).toEqual([0]); + expect(second.stack).toEqual([2]); + }); + }); + + describe('case-insensitivity', function () { + xit('DUP is case-insensitive', function () { + forth.evaluate('1 DUP Dup dup'); + expect(forth.stack).toEqual([1, 1, 1, 1]); + }); + xit('DROP is case-insensitive', function () { + forth.evaluate('1 2 3 4 DROP Drop drop'); + expect(forth.stack).toEqual([1]); + }); + xit('SWAP is case-insensitive', function () { + forth.evaluate('1 2 SWAP 3 Swap 4 swap'); + expect(forth.stack).toEqual([2, 3, 4, 1]); + }); + xit('OVER is case-insensitive', function () { + forth.evaluate('1 2 OVER Over over'); + expect(forth.stack).toEqual([1, 2, 1, 2, 1]); + }); + xit('user-defined words are case-insensitive', function () { + forth.evaluate(': foo dup ;'); + forth.evaluate('1 FOO Foo foo'); + expect(forth.stack).toEqual([1, 1, 1, 1]); + }); + xit('definitions are case-insensitive', function () { + forth.evaluate(': SWAP DUP Dup dup ;'); + forth.evaluate('1 swap'); + expect(forth.stack).toEqual([1, 1, 1, 1]); + }); + }); +}); diff --git a/exercises/gigasecond/README.md b/exercises/gigasecond/README.md index 4c73cb89..0bcf1777 100644 --- a/exercises/gigasecond/README.md +++ b/exercises/gigasecond/README.md @@ -6,26 +6,29 @@ A gigasecond is 10^9 (1,000,000,000) seconds. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine gigasecond.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/grade-school/README.md b/exercises/grade-school/README.md index 9a34bb7e..e9d6156a 100644 --- a/exercises/grade-school/README.md +++ b/exercises/grade-school/README.md @@ -21,7 +21,6 @@ In the end, you should be able to: Note that all our students only have one name. (It's a small town, what do you want?) - ## For bonus points Did you get the tests passing and the code clean? If you want to, these @@ -37,26 +36,29 @@ experiment make the code better? Worse? Did you learn anything from it? ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine grade-school.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/grade-school/example.js b/exercises/grade-school/example.js index f43c127e..2e81015c 100644 --- a/exercises/grade-school/example.js +++ b/exercises/grade-school/example.js @@ -1,11 +1,11 @@ module.exports = function School() { var db = {}; - function add(student, grade) { - if (db[grade]) { - db[grade].push(student); + function add(student, gradeLevel) { + if (db[gradeLevel]) { + db[gradeLevel].push(student); } else { - db[grade] = [student]; + db[gradeLevel] = [student]; } } @@ -14,8 +14,8 @@ module.exports = function School() { } function roster() { - return sortedGrades().reduce(function (sorted, grade) { - sorted[grade] = clone(db[grade]).sort(); + return sortedGrades().reduce(function (sorted, gradeLevel) { + sorted[gradeLevel] = clone(db[gradeLevel]).sort(); return sorted; }, {}); } diff --git a/exercises/grains/README.md b/exercises/grains/README.md index bac15508..f5600499 100644 --- a/exercises/grains/README.md +++ b/exercises/grains/README.md @@ -15,7 +15,6 @@ Write code that shows: - how many grains were on each square, and - the total number of grains - ## For bonus points Did you get the tests passing and the code clean? If you want to, these @@ -29,26 +28,29 @@ experiment make the code better? Worse? Did you learn anything from it? ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine grains.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/grains/example.js b/exercises/grains/example.js index 50077605..e8831fd2 100644 --- a/exercises/grains/example.js +++ b/exercises/grains/example.js @@ -4,7 +4,7 @@ var BigInt = require('./big-integer'); * @author github.com/nonsensery * @class Grains * - * Computes the number of grains on the squares of a + * @classdesc Computes the number of grains on the squares of a * chess board, starting with one grain on the first * square, and doubling with each successive square. */ @@ -14,16 +14,19 @@ function Grains() { /** * Gets the number of grains on the nth square. + * @param {number} num - the value to square + * @return {number} the square of num */ Grains.prototype.square = function (num) { - return BigInt(2).pow(num - 1).toString(); + return new BigInt(2).pow(num - 1).toString(); }; /** * Gets the total number of grains on all squares. + * @return {string} the total */ Grains.prototype.total = function () { - var total = BigInt(0); + var total = new BigInt(0); for (var squareNum = 1; squareNum <= 64; ++squareNum) { total = total.add(this.square(squareNum)); diff --git a/exercises/hamming/README.md b/exercises/hamming/README.md index f44a9feb..dcfd4d5b 100644 --- a/exercises/hamming/README.md +++ b/exercises/hamming/README.md @@ -37,26 +37,29 @@ of equal length differently. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine hamming.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/hello-world/HINTS.md b/exercises/hello-world/.meta/hints.md similarity index 100% rename from exercises/hello-world/HINTS.md rename to exercises/hello-world/.meta/hints.md diff --git a/exercises/hello-world/README.md b/exercises/hello-world/README.md index 7e71e8a7..3a36a6bd 100644 --- a/exercises/hello-world/README.md +++ b/exercises/hello-world/README.md @@ -103,26 +103,29 @@ When you are done, submit your solution to exercism: ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js - -In many test suites all but the first test have been skipped. +```sh +jasmine hello-world.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/hexadecimal/README.md b/exercises/hexadecimal/README.md index 022fe2bf..06e409dd 100644 --- a/exercises/hexadecimal/README.md +++ b/exercises/hexadecimal/README.md @@ -9,26 +9,29 @@ The program should handle invalid hexadecimal strings. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine hexadecimal.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/isbn-verifier/README.md b/exercises/isbn-verifier/README.md new file mode 100644 index 00000000..da1dbccf --- /dev/null +++ b/exercises/isbn-verifier/README.md @@ -0,0 +1,74 @@ +# Isbn Verifier + +The [ISBN-10 verification process](https://en.wikipedia.org/wiki/International_Standard_Book_Number) is used to validate book identification +numbers. These normally contain dashes and look like: `3-598-21508-8` + +## ISBN + +The ISBN-10 format is 9 digits (0 to 9) plus one check character (either a digit or an X only). In the case the check character is an X, this represents the value '10'. These may be communicated with or without hyphens, and can be checked for their validity by the following formula: + +``` +(x1 * 10 + x2 * 9 + x3 * 8 + x4 * 7 + x5 * 6 + x6 * 5 + x7 * 4 + x8 * 3 + x9 * 2 + x10 * 1) mod 11 == 0 +``` + +If the result is 0, then it is a valid ISBN-10, otherwise it is invalid. + +## Example + +Let's take the ISBN-10 `3-598-21508-8`. We plug it in to the formula, and get: +``` +(3 * 10 + 5 * 9 + 9 * 8 + 8 * 7 + 2 * 6 + 1 * 5 + 5 * 4 + 0 * 3 + 8 * 2 + 8 * 1) mod 11 == 0 +``` + +Since the result is 0, this proves that our ISBN is valid. + +## Task + +Given a string the program should check if the provided string is a valid ISBN-10. +Putting this into place requires some thinking about preprocessing/parsing of the string prior to calculating the check digit for the ISBN. + +The program should be able to verify ISBN-10 both with and without separating dashes. + + +## Caveats + +Converting from strings to numbers can be tricky in certain languages. +Now, it's even trickier since the check digit of an ISBN-10 may be 'X' (representing '10'). For instance `3-598-21507-X` is a valid ISBN-10. + +## Bonus tasks + +* Generate a valid ISBN-13 from the input ISBN-10 (and maybe verify it again with a derived verifier). + +* Generate valid ISBN, maybe even from a given starting ISBN. +## Setup + +Go through the setup instructions for JavaScript to install the + necessary dependencies: + +http://exercism.io/languages/javascript/installation + +## Running the test suite + +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: + +```sh +npm install -g jasmine +``` + +Run the test suite from the exercise directory with: + +```sh +jasmine isbn-verifier.spec.js +``` + +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. + +## Source + +Converting a string into a number and some basic processing utilizing a relatable real world example. [https://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-10_check_digit_calculation](https://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-10_check_digit_calculation) + +## 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/isbn-verifier/example.js b/exercises/isbn-verifier/example.js new file mode 100644 index 00000000..90ba4d31 --- /dev/null +++ b/exercises/isbn-verifier/example.js @@ -0,0 +1,24 @@ +'use strict'; + +function ISBN(isbn) { + this.isbn = isbn.replace(/-/g, ''); + + this.isValid = function () { + if (!this.isbn.match(/^(\d{9}[\dX])$/)) { + return false; + } + + var digits = this.isbn.split(''); + if (digits[9] === 'X') { + digits[9] = 10; + } + + var sum = digits.reduce(function (total, current, index) { + return total + ((10 - index) * parseInt(current, 10)); + }, 0); + + return sum % 11 === 0; + }; +} + +module.exports = ISBN; diff --git a/exercises/isbn-verifier/isbn-verifier.spec.js b/exercises/isbn-verifier/isbn-verifier.spec.js new file mode 100644 index 00000000..c6c4ff91 --- /dev/null +++ b/exercises/isbn-verifier/isbn-verifier.spec.js @@ -0,0 +1,68 @@ +var ISBN = require('./isbn-verifier'); + +describe('ISBN', function () { + it('valid isbn number', function () { + var isbn = new ISBN('3-598-21508-8'); + expect(isbn.isValid()).toBe(true); + }); + + it('invalid isbn check digit', function () { + var isbn = new ISBN('3-598-21508-9'); + expect(isbn.isValid()).toBe(false); + }); + + it('valid isbn number with a check digit of 10', function () { + var isbn = new ISBN('3-598-21507-X'); + expect(isbn.isValid()).toBe(true); + }); + + it('check digit is a character other than X', function () { + var isbn = new ISBN('3-598-21507-A'); + expect(isbn.isValid()).toBe(false); + }); + + it('invalid character in isbn', function () { + var isbn = new ISBN('3-598-2K507-0'); + expect(isbn.isValid()).toBe(false); + }); + + it('X is only valid as a check digit', function () { + var isbn = new ISBN('3-598-2X507-0'); + expect(isbn.isValid()).toBe(false); + }); + + it('valid isbn without separating dashes', function () { + var isbn = new ISBN('3598215088'); + expect(isbn.isValid()).toBe(true); + }); + + it('isbn without separating dashes and X as check digit', function () { + var isbn = new ISBN('359821507X'); + expect(isbn.isValid()).toBe(true); + }); + + it('isbn without check digit and dashes', function () { + var isbn = new ISBN('359821507'); + expect(isbn.isValid()).toBe(false); + }); + + it('too long isbn and no dashes', function () { + var isbn = new ISBN('3598215078X'); + expect(isbn.isValid()).toBe(false); + }); + + it('isbn without check digit', function () { + var isbn = new ISBN('3-598-21507'); + expect(isbn.isValid()).toBe(false); + }); + + it('too long isbn', function () { + var isbn = new ISBN('3-598-21507-XA'); + expect(isbn.isValid()).toBe(false); + }); + + it('check digit of X should not be used for 0', function () { + var isbn = new ISBN('3-598-21515-X'); + expect(isbn.isValid()).toBe(false); + }); +}); diff --git a/exercises/isogram/README.md b/exercises/isogram/README.md index 369373af..0b5ef9eb 100644 --- a/exercises/isogram/README.md +++ b/exercises/isogram/README.md @@ -2,38 +2,42 @@ Determine if a word or phrase is an isogram. -An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter. +An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times. Examples of isograms: - lumberjacks - background - downstream +- six-year-old The word *isograms*, however, is not an isogram, because the s repeats. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine isogram.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/kindergarten-garden/README.md b/exercises/kindergarten-garden/README.md index 15e4187d..515ef3af 100644 --- a/exercises/kindergarten-garden/README.md +++ b/exercises/kindergarten-garden/README.md @@ -3,19 +3,19 @@ Given a diagram, determine which plants each child in the kindergarten class is responsible for. -The kindergarten class is learning about growing plants. The teachers +The kindergarten class is learning about growing plants. The teacher thought it would be a good idea to give them actual seeds, plant them in actual dirt, and grow actual plants. They've chosen to grow grass, clover, radishes, and violets. -To this end, they've put little styrofoam cups along the window sills, -and planted one type of plant in each cup, choosing randomly from the -available types of seeds. +To this end, the children have put little cups along the window sills, and +planted one type of plant in each cup, choosing randomly from the available +types of seeds. -```plain +```text [window][window][window] -........................ # each dot represents a styrofoam cup +........................ # each dot represents a cup ........................ ``` @@ -25,27 +25,27 @@ There are 12 children in the class: - Eve, Fred, Ginny, Harriet, - Ileana, Joseph, Kincaid, and Larry. -Each child gets 4 cups, two on each row. The children are assigned to -cups in alphabetical order. +Each child gets 4 cups, two on each row. Their teacher assigns cups to +the children alphabetically by their names. The following diagram represents Alice's plants: -```plain +```text [window][window][window] VR...................... RG...................... ``` -So in the row nearest the window, she has a violet and a radish; in the -row behind that, she has a radish and some grass. +In the first row, nearest the windows, she has a violet and a radish. In the +second row she has a radish and some grass. Your program will be given the plants from left-to-right starting with the row nearest the windows. From this, it should be able to determine -which plants belong to which students. +which plants belong to each student. For example, if it's told that the garden looks like so: -```plain +```text [window][window][window] VRCGVVRVCGGCCGVRGCVCGCGV VRCCCGCRRGVCGCRVVCVGCGCV @@ -61,26 +61,29 @@ While asking for Bob's plants would yield: ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js - -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine kindergarten-garden.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/kindergarten-garden/example.js b/exercises/kindergarten-garden/example.js index 725585b1..0fc7f6c4 100644 --- a/exercises/kindergarten-garden/example.js +++ b/exercises/kindergarten-garden/example.js @@ -23,13 +23,13 @@ var plants = { }; function getPlants(pots, index) { - var plants = []; + var plantsArr = []; var position = 2 * index; - plants.push(pots[0][position]); - plants.push(pots[0][position + 1]); - plants.push(pots[1][position]); - plants.push(pots[1][position + 1]); - return plants; + plantsArr.push(pots[0][position]); + plantsArr.push(pots[0][position + 1]); + plantsArr.push(pots[1][position]); + plantsArr.push(pots[1][position + 1]); + return plantsArr; } function parse(diagram) { @@ -42,10 +42,10 @@ function parse(diagram) { function Garden(diagram, students) { var instance = {}; - students = students || defaultChildren; - students.sort(); + var kids = students || defaultChildren; + kids.sort(); - students.forEach(function (student, index) { + kids.forEach(function (student, index) { instance[student.toLowerCase()] = getPlants(parse(diagram), index); }); diff --git a/exercises/largest-series-product/README.md b/exercises/largest-series-product/README.md index 1d56a017..80ef954b 100644 --- a/exercises/largest-series-product/README.md +++ b/exercises/largest-series-product/README.md @@ -15,26 +15,29 @@ the largest product for a series of 6 digits is 23520. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine largest-series-product.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/largest-series-product/example.js b/exercises/largest-series-product/example.js index 2e074103..fa5e5272 100644 --- a/exercises/largest-series-product/example.js +++ b/exercises/largest-series-product/example.js @@ -14,7 +14,8 @@ Series.prototype.getDigits = function () { Series.prototype.largestProduct = function (size) { if (size < 0) throw new Error('Invalid input.'); - var product, max = 0; + var product; + var max = 0; this.slices(size).forEach(function (slice) { product = slice.reduce(function (a, b) { return a * b; diff --git a/exercises/leap/README.md b/exercises/leap/README.md index 8f87cfcb..1797b780 100644 --- a/exercises/leap/README.md +++ b/exercises/leap/README.md @@ -4,7 +4,7 @@ Given a year, report if it is a leap year. The tricky thing here is that a leap year in the Gregorian calendar occurs: -```plain +```text on every year that is evenly divisible by 4 except every year that is evenly divisible by 100 unless the year is also evenly divisible by 400 @@ -28,26 +28,29 @@ phenomenon, go watch [this youtube video][video]. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js - -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine leap.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/leap/example.js b/exercises/leap/example.js index bbe7eceb..653dbe45 100644 --- a/exercises/leap/example.js +++ b/exercises/leap/example.js @@ -3,9 +3,11 @@ /** * Represents a year to check whether is leap or not * - * @param {number} year + * @param {number} year + * * Numeric year. */ + function Year(year) { this.year = year; } @@ -13,11 +15,13 @@ function Year(year) { /** * Whether given year is a leap year. * - * @return {boolean} + * @returns {boolean} + * * Whether given year is a leap year. */ + Year.prototype.isLeap = function () { - return (this.year % 400 == 0) || ((this.year % 4 == 0) && (this.year % 100 != 0)); + return (this.year % 400 === 0) || ((this.year % 4 === 0) && (this.year % 100 !== 0)); }; module.exports = Year; diff --git a/exercises/leap/leap.js b/exercises/leap/leap.js index 22b6bb5c..5329bf2d 100644 --- a/exercises/leap/leap.js +++ b/exercises/leap/leap.js @@ -3,10 +3,10 @@ // convenience to get you started writing code faster. // -var Year = function (input) { +var Year = function () { // // YOUR CODE GOES HERE -// +// }; Year.prototype.isLeap = function () { diff --git a/exercises/linked-list/README.md b/exercises/linked-list/README.md index d719f252..e7b5e704 100644 --- a/exercises/linked-list/README.md +++ b/exercises/linked-list/README.md @@ -2,18 +2,18 @@ Implement a doubly linked list. -Like an array, a linked list is a simple linear data structure. Several -common data types can be implemented using linked lists, like queues, +Like an array, a linked list is a simple linear data structure. Several +common data types can be implemented using linked lists, like queues, stacks, and associative arrays. -A linked list is a collection of data elements called *nodes*. In a -*singly linked list* each node holds a value and a link to the next node. -In a *doubly linked list* each node also holds a link to the previous +A linked list is a collection of data elements called *nodes*. In a +*singly linked list* each node holds a value and a link to the next node. +In a *doubly linked list* each node also holds a link to the previous node. -You will write an implementation of a doubly linked list. Implement a -Node to hold a value and pointers to the next and previous nodes. Then -implement a List which holds references to the first and last node and +You will write an implementation of a doubly linked list. Implement a +Node to hold a value and pointers to the next and previous nodes. Then +implement a List which holds references to the first and last node and offers an array-like interface for adding and removing items: * `push` (*insert value at back*); @@ -21,34 +21,37 @@ offers an array-like interface for adding and removing items: * `shift` (*remove value at front*). * `unshift` (*insert value at front*); -To keep your implementation simple, the tests will not cover error -conditions. Specifically: `pop` or `shift` will never be called on an +To keep your implementation simple, the tests will not cover error +conditions. Specifically: `pop` or `shift` will never be called on an empty list. If you want to know more about linked lists, check [Wikipedia](https://en.wikipedia.org/wiki/Linked_list). ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine linked-list.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/linked-list/example.js b/exercises/linked-list/example.js index 7c288bfa..672dff0c 100644 --- a/exercises/linked-list/example.js +++ b/exercises/linked-list/example.js @@ -10,7 +10,7 @@ function LinkedList() { this._front = null; } -LinkedList.prototype.push = function LinkedList_push(value) { +LinkedList.prototype.push = function (value) { if (this._front === null) { this._front = new Node(value); } else { @@ -21,18 +21,18 @@ LinkedList.prototype.push = function LinkedList_push(value) { } }; -LinkedList.prototype.unshift = function LinkedList_unshift(value) { +LinkedList.prototype.unshift = function (value) { this.push(value); this._front = this._front.prev; }; -LinkedList.prototype.pop = function LinkedList_pop() { - if (this._front === null) {return undefined;} +LinkedList.prototype.pop = function () { + if (this._front === null) {return null;} this._front = this._front.prev; return this.shift(); }; -LinkedList.prototype.shift = function LinkedList_shift() { +LinkedList.prototype.shift = function () { var value = this._front.value; var front = this._front.next; var back = this._front.prev; @@ -63,7 +63,7 @@ LinkedList.prototype.delete = function (match) { this._front.next = this._front.next.next; } else { this._front = this._front.next; - return this.delete(match); + this.delete(match); } }; diff --git a/exercises/list-ops/README.md b/exercises/list-ops/README.md index cfbf36e6..44da25f4 100644 --- a/exercises/list-ops/README.md +++ b/exercises/list-ops/README.md @@ -8,27 +8,29 @@ without using existing functions. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.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`. +```sh +jasmine list-ops.spec.js +``` +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## 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/list-ops/example.js b/exercises/list-ops/example.js index c32141e7..f47d84b9 100644 --- a/exercises/list-ops/example.js +++ b/exercises/list-ops/example.js @@ -56,7 +56,7 @@ List.prototype = { return new List(this.foldl(this.cons, [])); }, - map: function (func, arr) { + map: function (func) { var applyFuncThenCons = function (x, acc) { return this.cons(func(x), acc); }; diff --git a/exercises/luhn/README.md b/exercises/luhn/README.md index 217faccc..e11e1bf3 100644 --- a/exercises/luhn/README.md +++ b/exercises/luhn/README.md @@ -18,27 +18,27 @@ are disallowed. ## Example 1: valid credit card number -``` +```text 4539 1488 0343 6467 ``` The first step of the Luhn algorithm is to double every second digit, starting from the right. We will be doubling -``` +```text 4_3_ 1_8_ 0_4_ 6_6_ ``` If doubling the number results in a number greater than 9 then subtract 9 from the product. The results of our doubling: -``` +```text 8569 2478 0383 3437 ``` Then sum all of the digits: -``` +```text 8+5+6+9+2+4+7+8+0+3+8+3+3+4+3+7 = 80 ``` @@ -46,19 +46,19 @@ If the sum is evenly divisible by 10, then the number is valid. This number is v ## Example 2: invalid credit card number -``` +```text 8273 1232 7352 0569 ``` Double the second digits, starting from the right -``` +```text 7253 2262 5312 0539 ``` Sum the digits -``` +```text 7+2+5+3+2+2+6+2+5+3+1+2+0+5+3+9 = 57 ``` @@ -66,26 +66,29 @@ Sum the digits ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine luhn.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/luhn/example.js b/exercises/luhn/example.js index b311427f..cc38e98f 100644 --- a/exercises/luhn/example.js +++ b/exercises/luhn/example.js @@ -1,8 +1,8 @@ 'use strict'; function isValid(number) { - number = number.replace(/\s/g, ''); - const digits = [...number]; + var numbers = number.replace(/\s/g, ''); + const digits = [...numbers]; const sum = digits // convert to integers diff --git a/exercises/matrix/README.md b/exercises/matrix/README.md index 3b427e26..dd2504ef 100644 --- a/exercises/matrix/README.md +++ b/exercises/matrix/README.md @@ -5,13 +5,15 @@ that matrix. So given a string with embedded newlines like: -> 9 8 7 -> 5 3 2 -> 6 6 7 +```text +9 8 7 +5 3 2 +6 6 7 +``` representing this matrix: -```plain +```text 0 1 2 |--------- 0 | 9 8 7 @@ -40,26 +42,29 @@ And its columns: ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine matrix.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/meetup/README.md b/exercises/meetup/README.md index fb20f112..95f902ee 100644 --- a/exercises/meetup/README.md +++ b/exercises/meetup/README.md @@ -2,49 +2,55 @@ Calculate the date of meetups. -Typically meetups happen on the same day of the week. In this exercise, you will take -a description of a meetup date, and return the actual meetup date. +Typically meetups happen on the same day of the week. In this exercise, you +will take a description of a meetup date, and return the actual meetup date. Examples of general descriptions are: -- the first Monday of January 2017 -- the third Tuesday of January 2017 -- the Wednesteenth of January 2017 -- the last Thursday of January 2017 +- The first Monday of January 2017 +- The third Tuesday of January 2017 +- The wednesteenth of January 2017 +- The last Thursday of January 2017 -Note that "Monteenth", "Tuesteenth", etc are all made up words. There -was a meetup whose members realized that there are exactly 7 numbered days in a month that -end in '-teenth'. Therefore, one is guaranteed that each day of the week +The descriptors you are expected to parse are: +first, second, third, fourth, fifth, last, monteenth, tuesteenth, wednesteenth, +thursteenth, friteenth, saturteenth, sunteenth + +Note that "monteenth", "tuesteenth", etc are all made up words. There was a +meetup whose members realized that there are exactly 7 numbered days in a month +that end in '-teenth'. Therefore, one is guaranteed that each day of the week (Monday, Tuesday, ...) will have exactly one date that is named with '-teenth' in every month. -Given examples of a meetup dates, each containing a month, day, year, and descriptor -(first, second, teenth, etc), calculate the date of the actual meetup. -For example, if given "First Monday of January 2017", the correct meetup date is 2017/1/2 - +Given examples of a meetup dates, each containing a month, day, year, and +descriptor calculate the date of the actual meetup. For example, if given +"The first Monday of January 2017", the correct meetup date is 2017/1/2. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine meetup.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/minesweeper/README.md b/exercises/minesweeper/README.md index 6b0e55de..f3890756 100644 --- a/exercises/minesweeper/README.md +++ b/exercises/minesweeper/README.md @@ -28,27 +28,29 @@ into this: ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.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`. +```sh +jasmine minesweeper.spec.js +``` +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## 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/minesweeper/example.js b/exercises/minesweeper/example.js index b5d76036..a366884e 100644 --- a/exercises/minesweeper/example.js +++ b/exercises/minesweeper/example.js @@ -21,25 +21,25 @@ Minesweeper.prototype.annotate = function (rows) { } var board = rows.map(function (row) { return row.split(''); }); var outBoard = []; - for (var x = 0; x < board.length; x++) { + board.forEach(function (memberX, x) { outBoard[x] = []; - for (var y = 0; y < board[x].length; y++) { - var spot = board[x][y]; + memberX.forEach(function (memberXY, y) { + var spot = memberXY; if (spot === '*') { outBoard[x][y] = spot; - continue; + } else { + var bombCount = this.distanceXdistanceYs.map(function (dxdy) { + if (typeof board[x + dxdy[0]] === 'undefined') { + return 0; + } + return board[x + dxdy[0]][y + dxdy[1]] === '*' ? 1 : 0; + }).reduce(function (total, num) { + return total + num; + }); + outBoard[x][y] = bombCount > 0 ? bombCount : ' '; } - var bombCount = this.distanceXdistanceYs.map(function (dxdy) { - if (board[x + dxdy[0]] === undefined) { - return 0; - } - return board[x + dxdy[0]][y + dxdy[1]] === '*' ? 1 : 0; - }).reduce(function (total, num) { - return total + num; - }); - outBoard[x][y] = bombCount > 0 ? bombCount : ' '; - } - } + }, this); + }, this); return outBoard.map(function (row) { return row.join(''); }); diff --git a/exercises/nth-prime/README.md b/exercises/nth-prime/README.md index 84bae01d..621e625a 100644 --- a/exercises/nth-prime/README.md +++ b/exercises/nth-prime/README.md @@ -10,26 +10,29 @@ numbers, pretend they don't exist and implement them yourself. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine nth-prime.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/nth-prime/example.js b/exercises/nth-prime/example.js index f0d824dc..5deed40c 100644 --- a/exercises/nth-prime/example.js +++ b/exercises/nth-prime/example.js @@ -3,16 +3,21 @@ module.exports = { nth: function (nthPrime) { if (nthPrime === 0) { throw new Error('Prime is not possible'); } - this.generatePrimes(200000); + + // Using prime number theory to approximate the prime + // See https://en.wikipedia.org/wiki/Prime_number_theorem#Approximations_for_the_nth_prime_number + var upperBound = (nthPrime + 2) * Math.log((nthPrime + 2) * Math.log((nthPrime + 2))); + this.generatePrimes(upperBound); return this.realPrimes[nthPrime - 1]; }, generatePrimes: function (uptoNumber) { - var i, j, currentPrime, primeCount, possiblePrimes = []; - - if (this.realPrimes) { return this.realPrimes; } + var i; + var j; + var currentPrime; + var possiblePrimes = []; for (i = 2; i <= uptoNumber; i++) { - possiblePrimes.push({ number: i, prime: true}); + possiblePrimes.push({ number: i, prime: true }); } for (i = 2; i < Math.sqrt(possiblePrimes.length); i++) { @@ -24,8 +29,6 @@ module.exports = { } } - primeCount = 0; - this.realPrimes = []; for (i = 0; i < possiblePrimes.length; i++) { @@ -34,6 +37,7 @@ module.exports = { this.realPrimes.push(currentPrime.number); } } + return this.realPrimes; } }; diff --git a/exercises/nth-prime/nth-prime.spec.js b/exercises/nth-prime/nth-prime.spec.js index 727ce507..70a326d8 100644 --- a/exercises/nth-prime/nth-prime.spec.js +++ b/exercises/nth-prime/nth-prime.spec.js @@ -17,6 +17,14 @@ describe('Prime', function () { expect(prime.nth(10001)).toEqual(104743); }); + xit('massive prime', function () { + expect(prime.nth(20000)).toEqual(224737); + }); + + xit('extreme prime', function () { + expect(prime.nth(30000)).toEqual(350377); + }); + xit('weird case', function () { expect( function () { prime.nth(0); diff --git a/exercises/nucleotide-count/README.md b/exercises/nucleotide-count/README.md index 8f0622dc..607c27c5 100644 --- a/exercises/nucleotide-count/README.md +++ b/exercises/nucleotide-count/README.md @@ -1,53 +1,42 @@ # Nucleotide Count -Given a DNA string, compute how many times each nucleotide occurs in the string. +Given a single stranded DNA string, compute how many times each nucleotide occurs in the string. -DNA is represented by an alphabet of the following symbols: 'A', 'C', -'G', and 'T'. - -Each symbol represents a nucleotide, which is a fancy name for the -particular molecules that happen to make up a large part of DNA. - -Shortest intro to biochemistry EVAR: +The genetic language of every living thing on the planet is DNA. +DNA is a large molecule that is built from an extremely long sequence of individual elements called nucleotides. +4 types exist in DNA and these differ only slightly and can be represented as the following symbols: 'A' for adenine, 'C' for cytosine, 'G' for guanine, and 'T' thymine. +Here is an analogy: - twigs are to birds nests as -- nucleotides are to DNA and RNA as -- amino acids are to proteins as -- sugar is to starch as -- oh crap lipids - -I'm not going to talk about lipids because they're crazy complex. - -So back to nucleotides. - -DNA contains four types of them: adenine (`A`), cytosine (`C`), guanine -(`G`), and thymine (`T`). - -RNA contains a slightly different set of nucleotides, but we don't care -about that for now. +- nucleotides are to DNA as +- legos are to lego houses as +- words are to sentences as... ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine nucleotide-count.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/ocr-numbers/README.md b/exercises/ocr-numbers/README.md index 0a7e5338..5444b695 100644 --- a/exercises/ocr-numbers/README.md +++ b/exercises/ocr-numbers/README.md @@ -1,4 +1,4 @@ -# Ocr Numbers +# OCR Numbers Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is represented, or whether it is garbled. @@ -9,7 +9,7 @@ To begin with, convert a simple binary font to a string containing 0 or 1. The binary font uses pipes and underscores, four rows high and three columns wide. -``` +```text _ # | | # zero. |_| # @@ -18,7 +18,7 @@ The binary font uses pipes and underscores, four rows high and three columns wid Is converted to "0" -``` +```text # | # one. | # @@ -39,7 +39,7 @@ Update your program to recognize multi-character binary strings, replacing garbl Update your program to recognize all numbers 0 through 9, both individually and as part of a larger string. -``` +```text _ _| |_ @@ -48,7 +48,7 @@ Update your program to recognize all numbers 0 through 9, both individually and Is converted to "2" -``` +```text _ _ _ _ _ _ _ _ # | _| _||_||_ |_ ||_||_|| | # decimal numbers. ||_ _| | _||_| ||_| _||_| # @@ -61,7 +61,7 @@ Is converted to "1234567890" Update your program to handle multiple numbers, one per line. When converting several lines, join the lines with commas. -``` +```text _ _ | _| _| ||_ _| @@ -80,26 +80,29 @@ Is converted to "123,456,789" ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine ocr-numbers.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/octal/README.md b/exercises/octal/README.md index a791ac8d..1e906436 100644 --- a/exercises/octal/README.md +++ b/exercises/octal/README.md @@ -8,11 +8,13 @@ Implement octal to decimal conversion. Given an octal input string, your program should produce a decimal output. ## Note + - Implement the conversion yourself. Do not use something else to perform the conversion for you. - Treat invalid input as octal 0. ## About Octal (Base-8) + Decimal is a base-10 system. A number 233 in base 10 notation can be understood @@ -25,7 +27,8 @@ as a linear combination of powers of 10: - All these values are summed. So: -``` + +```text 233 # decimal = 2*10^2 + 3*10^1 + 3*10^0 = 2*100 + 3*10 + 3*1 @@ -34,7 +37,8 @@ So: Octal is similar, but uses powers of 8 rather than powers of 10. So: -``` + +```text 233 # octal = 2*8^2 + 3*8^1 + 3*8^0 = 2*64 + 3*8 + 3*1 @@ -44,26 +48,29 @@ So: ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine octal.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/octal/example.js b/exercises/octal/example.js index 1b66b739..535d0556 100644 --- a/exercises/octal/example.js +++ b/exercises/octal/example.js @@ -17,7 +17,7 @@ Octal.prototype.digitValue = function (value) { }; Octal.prototype.accumulator = function (decimal, digit, index) { - return decimal += digit * Math.pow(BASE, index); + return decimal + digit * Math.pow(BASE, index); }; module.exports = Octal; diff --git a/exercises/palindrome-products/README.md b/exercises/palindrome-products/README.md index c324677c..29c8035b 100644 --- a/exercises/palindrome-products/README.md +++ b/exercises/palindrome-products/README.md @@ -5,56 +5,58 @@ Detect palindrome products in a given range. A palindromic number is a number that remains the same when its digits are reversed. For example, `121` is a palindromic number but `112` is not. -Given the definition of a palindromic number, we define a palindrome _product_ -to be the product `c`, such that `a * b = c`, where `c` is a palindromic number and - `a` and `b` are integers (possibly, but _not_ necessarily palindromic numbers). +Given a range of numbers, find the largest and smallest palindromes which +are products of numbers within that range. -For example, the palindromic number 9009 can be written as the palindrome -product: `91 * 99 = 9009`. - -It's possible (and indeed common) for a palindrome product to be the product -of multiple combinations of numbers. For example, the palindrome product `9` has -the factors `(1, 9)`, `(3, 3)`, and `(9, 1)`. - -Write a program that, given a range of integers, returns the smallest and largest -palindromic product within that range, along with all of its factors. +Your solution should return the largest and smallest palindromes, along with the +factors of each within the range. If the largest or smallest palindrome has more +than one pair of factors within the range, then return all the pairs. ## Example 1 Given the range `[1, 9]` (both inclusive)... -The smallest product is `1`. Its factors are `(1, 1)`. -The largest product is `9`. Its factors are `(1, 9)`, `(3, 3)`, and `(9, 1)`. +And given the list of all possible products within this range: +`[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 15, 21, 24, 27, 20, 28, 32, 36, 25, 30, 35, 40, 45, 42, 48, 54, 49, 56, 63, 64, 72, 81]` + +The palindrome products are all single digit numbers (in this case): +`[1, 2, 3, 4, 5, 6, 7, 8, 9]` + +The smallest palindrome product is `1`. Its factors are `(1, 1)`. +The largest palindrome product is `9`. Its factors are `(1, 9)` and `(3, 3)`. ## Example 2 Given the range `[10, 99]` (both inclusive)... The smallest palindrome product is `121`. Its factors are `(11, 11)`. -The largest palindrome product is `9009`. Its factors are `(91, 99)` and `(99, 91)`. +The largest palindrome product is `9009`. Its factors are `(91, 99)`. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine palindrome-products.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/palindrome-products/example.js b/exercises/palindrome-products/example.js index 5928bdb2..ab242849 100644 --- a/exercises/palindrome-products/example.js +++ b/exercises/palindrome-products/example.js @@ -14,16 +14,16 @@ module.exports = function Palindromes(options) { for (var i = minFactor; i <= maxFactor; i++) { for (var j = minFactor; j <= maxFactor; j++) { var result = i * j; - if ( ! this.isPalindrome(result) ) { continue; } + if (!this.isPalindrome(result)) { continue; } var newFactor = [i, j].sort(); - if (palindromes[result] === undefined) { + if (!Array.isArray(palindromes[result])) { palindromes[result] = []; palindromeIndexes.push(result); } - if ( ! arrayContainsArray(palindromes[result], newFactor) ) { + if (!arrayContainsArray(palindromes[result], newFactor)) { palindromes[result].push(newFactor); } } diff --git a/exercises/pangram/README.md b/exercises/pangram/README.md index 9fceecd9..d94827f5 100644 --- a/exercises/pangram/README.md +++ b/exercises/pangram/README.md @@ -2,7 +2,7 @@ Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. -The best known English pangram is: +The best known English pangram is: > The quick brown fox jumps over the lazy dog. The alphabet used consists of ASCII letters `a` to `z`, inclusive, and is case @@ -10,26 +10,29 @@ insensitive. Input will not contain non-ASCII symbols. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine pangram.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/pangram/example.js b/exercises/pangram/example.js index e6d8a7c6..86922be7 100644 --- a/exercises/pangram/example.js +++ b/exercises/pangram/example.js @@ -1,9 +1,10 @@ -var notAlpha = /[^a-z]+/gi, - ALPHA_LENGTH = 26, - cleaned, - unique; var Pangram = function (candidate) { + var notAlpha = /[^a-z]+/gi; + var ALPHA_LENGTH = 26; + var cleaned; + var unique; + unique = {}; cleaned = (candidate.replace(notAlpha, '')).toLowerCase(); cleaned.split('').forEach(function (el) { diff --git a/exercises/pangram/pangram.spec.js b/exercises/pangram/pangram.spec.js index 74197329..b2bae495 100644 --- a/exercises/pangram/pangram.spec.js +++ b/exercises/pangram/pangram.spec.js @@ -1,23 +1,28 @@ var Pangram = require('./pangram'); describe('Pangram()', function () { - it('empty sentence', function () { + it('sentence empty', function () { var pangram = new Pangram(''); expect(pangram.isPangram()).toBe(false); }); + xit('recognizes a perfect lower case pangram', function () { + var pangram = new Pangram('abcdefghijklmnopqrstuvwxyz'); + expect(pangram.isPangram()).toBe(true); + }); + xit('pangram with only lower case', function () { var pangram = new Pangram('the quick brown fox jumps over the lazy dog'); expect(pangram.isPangram()).toBe(true); }); - xit("missing character 'x'", function () { + xit("missing character 'x'", function () { var pangram = new Pangram('a quick movement of the enemy will jeopardize five gunboats'); expect(pangram.isPangram()).toBe(false); }); - xit("another missing character 'x'", function () { - var pangram = new Pangram('the quick brown fish jumps over the lazy dog'); + xit("another missing character, e.g. 'h'", function () { + var pangram = new Pangram('five boxing wizards jump quickly at it'); expect(pangram.isPangram()).toBe(false); }); @@ -27,22 +32,22 @@ describe('Pangram()', function () { }); xit('pangram with numbers', function () { - var pangram = new Pangram('the 1 quick brown fox jumps over the 2 lazy dogs'); + var pangram = new Pangram('the 1 quick brown fox jumps over the 2 lazy dog'); expect(pangram.isPangram()).toBe(true); }); - xit('missing letters replaced by numbers', function () { + xit('missing letters replaced by numbers', function () { var pangram = new Pangram('7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog'); expect(pangram.isPangram()).toBe(false); }); xit('pangram with mixed case and punctuation', function () { - var pangram = new Pangram('"Five quacking Zephyrs jolt my wax bed."'); + var pangram = new Pangram('\"Five quacking Zephyrs jolt my wax bed.\"'); expect(pangram.isPangram()).toBe(true); }); - xit('pangram with non-ascii characters', function () { - var pangram = new Pangram('Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.'); - expect(pangram.isPangram()).toBe(true); + xit('upper and lower case versions of the same character should not be counted separately', function () { + var pangram = new Pangram('the quick brown fox jumps over with lazy FX'); + expect(pangram.isPangram()).toBe(false); }); }); diff --git a/exercises/pascals-triangle/README.md b/exercises/pascals-triangle/README.md index cf72686d..4011ad75 100644 --- a/exercises/pascals-triangle/README.md +++ b/exercises/pascals-triangle/README.md @@ -1,11 +1,11 @@ -# Pascals Triangle +# Pascal's Triangle Compute Pascal's triangle up to a given number of rows. In Pascal's Triangle each number is computed by adding the numbers to the right and left of the current position in the previous row. -```plain +```text 1 1 1 1 2 1 @@ -16,26 +16,29 @@ the right and left of the current position in the previous row. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js - -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine pascals-triangle.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/perfect-numbers/README.md b/exercises/perfect-numbers/README.md index 4e343f53..4f9eaabe 100644 --- a/exercises/perfect-numbers/README.md +++ b/exercises/perfect-numbers/README.md @@ -5,7 +5,7 @@ Nicomachus' (60 - 120 CE) classification scheme for natural numbers. The Greek mathematician [Nicomachus](https://en.wikipedia.org/wiki/Nicomachus) devised a classification scheme for natural numbers, identifying each as belonging uniquely to the categories of **perfect**, **abundant**, or **deficient** based on their [aliquot sum](https://en.wikipedia.org/wiki/Aliquot_sum). The aliquot sum is defined as the sum of the factors of a number not including the number itself. For example, the aliquot sum of 15 is (1 + 3 + 5) = 9 -- **Perfect**: aliquot sum = number +- **Perfect**: aliquot sum = number - 6 is a perfect number because (1 + 2 + 3) = 6 - 28 is a perfect number because (1 + 2 + 4 + 7 + 14) = 28 - **Abundant**: aliquot sum > number @@ -14,31 +14,34 @@ The Greek mathematician [Nicomachus](https://en.wikipedia.org/wiki/Nicomachus) d - **Deficient**: aliquot sum < number - 8 is a deficient number because (1 + 2 + 4) = 7 - Prime numbers are deficient - + Implement a way to determine whether a given number is **perfect**. Depending on your language track, you may also need to implement a way to determine whether a given number is **abundant** or **deficient**. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine perfect-numbers.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/perfect-numbers/example.js b/exercises/perfect-numbers/example.js index c7fcdd76..ad7c1c6e 100644 --- a/exercises/perfect-numbers/example.js +++ b/exercises/perfect-numbers/example.js @@ -7,10 +7,12 @@ var PerfectNumbers = function () { /** * Calculate all the divisors for a given number and return them as an array. * Note: the actual number is not include in the returned array. + * @param {number} number - a number input. + * @returns {array} - the array of divisors */ PerfectNumbers.prototype.getDivisors = function (number) { var i; - var divs = new Array(); + var divs = []; // Accepts only natura numbers greater than 1. if (number <= 1) { @@ -31,7 +33,9 @@ PerfectNumbers.prototype.getDivisors = function (number) { }; PerfectNumbers.prototype.classify = function (number) { - var i, sum, result; + var i; + var sum; + var result; // Check if the input is valid if (number <= 0) { diff --git a/exercises/phone-number/README.md b/exercises/phone-number/README.md index c0428ad7..12968e23 100644 --- a/exercises/phone-number/README.md +++ b/exercises/phone-number/README.md @@ -6,14 +6,15 @@ The **North American Numbering Plan (NANP)** is a telephone numbering system use NANP numbers are ten-digit numbers consisting of a three-digit Numbering Plan Area code, commonly known as *area code*, followed by a seven-digit local number. The first three digits of the local number represent the *exchange code*, followed by the unique four-digit number which is the *subscriber number*. - The format is usually represented as -``` + +```text (NXX)-NXX-XXXX ``` + where `N` is any digit from 2 through 9 and `X` is any digit from 0 through 9. -Your task is to clean up differently formated telephone numbers by removing punctuation and the country code (1) if present. +Your task is to clean up differently formatted telephone numbers by removing punctuation and the country code (1) if present. For example, the inputs - `+1 (613)-995-0253` @@ -29,26 +30,29 @@ should all produce the output ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js - -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine phone-number.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/pig-latin/README.md b/exercises/pig-latin/README.md index cfd1f0e9..4a1cc7da 100644 --- a/exercises/pig-latin/README.md +++ b/exercises/pig-latin/README.md @@ -19,26 +19,29 @@ See for more details. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine pig-latin.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/point-mutations/README.md b/exercises/point-mutations/README.md index b479abc5..a7136a5c 100644 --- a/exercises/point-mutations/README.md +++ b/exercises/point-mutations/README.md @@ -36,26 +36,29 @@ distance function. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine point-mutations.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/prime-factors/README.md b/exercises/prime-factors/README.md index eefc5599..ed083464 100644 --- a/exercises/prime-factors/README.md +++ b/exercises/prime-factors/README.md @@ -31,26 +31,29 @@ You can check this yourself: ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine prime-factors.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/protein-translation/README.md b/exercises/protein-translation/README.md index 0c163fe0..96e516e5 100644 --- a/exercises/protein-translation/README.md +++ b/exercises/protein-translation/README.md @@ -10,17 +10,17 @@ Codons: `"AUG", "UUU", "UCU"` => which become a polypeptide with the following sequence => Protein: `"Methionine", "Phenylalanine", "Serine"` - + There are 64 codons which in turn correspond to 20 amino acids; however, all of the codon sequences and resulting amino acids are not important in this exercise. If it works for one codon, the program should work for all of them. -However, feel free to expand the list in the test suite to include them all. +However, feel free to expand the list in the test suite to include them all. -There are also four terminating codons (also known as 'STOP' codons); if any of these codons are encountered (by the ribosome), all translation ends and the protein is terminated. +There are also three terminating codons (also known as 'STOP' codons); if any of these codons are encountered (by the ribosome), all translation ends and the protein is terminated. All subsequent codons after are ignored, like this: RNA: `"AUGUUUUCUUAAAUG"` => -Codons: `"AUG", "UUU", "UCU", "UAG", "AUG"` => +Codons: `"AUG", "UUU", "UCU", "UAG", "AUG"` => Protein: `"Methionine", "Phenylalanine", "Serine"` @@ -39,31 +39,33 @@ UGU, UGC | Cysteine UGG | Tryptophan UAA, UAG, UGA | STOP - Learn more about [protein translation on Wikipedia](http://en.wikipedia.org/wiki/Translation_(biology)) ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine protein-translation.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/proverb/README.md b/exercises/proverb/README.md index 51fdaac1..b7282a20 100644 --- a/exercises/proverb/README.md +++ b/exercises/proverb/README.md @@ -1,38 +1,46 @@ # Proverb -For want of a horseshoe nail, a kingdom was lost, or so the saying goes. Output -the full text of this proverbial rhyme: +For want of a horseshoe nail, a kingdom was lost, or so the saying goes. -> For want of a nail the shoe was lost. -> For want of a shoe the horse was lost. -> For want of a horse the rider was lost. -> For want of a rider the message was lost. -> For want of a message the battle was lost. -> For want of a battle the kingdom was lost. -> And all for the want of a horseshoe nail. +Given a list of inputs, generate the relevant proverb. For example, given the list `["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"]`, you will output the full text of this proverbial rhyme: -## Setup +```text +For want of a nail the shoe was lost. +For want of a shoe the horse was lost. +For want of a horse the rider was lost. +For want of a rider the message was lost. +For want of a message the battle was lost. +For want of a battle the kingdom was lost. +And all for the want of a nail. +``` + +Note that the list of inputs may vary; your solution should be able to handle lists of arbitrary length and content. No line of the output text should be a static, unchanging string; all should vary according to the input given. -Go through the setup instructions for JavaScript to -install the necessary dependencies: +## Setup -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine proverb.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/pythagorean-triplet/README.md b/exercises/pythagorean-triplet/README.md index 7165790b..fc3b3b94 100644 --- a/exercises/pythagorean-triplet/README.md +++ b/exercises/pythagorean-triplet/README.md @@ -3,13 +3,13 @@ A Pythagorean triplet is a set of three natural numbers, {a, b, c}, for which, -``` +```text a**2 + b**2 = c**2 ``` -For example, +For example, -``` +```text 3**2 + 4**2 = 9 + 16 = 25 = 5**2. ``` @@ -19,26 +19,29 @@ Find the product a * b * c. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine pythagorean-triplet.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/pythagorean-triplet/example.js b/exercises/pythagorean-triplet/example.js index 44f4edf4..a30323bc 100644 --- a/exercises/pythagorean-triplet/example.js +++ b/exercises/pythagorean-triplet/example.js @@ -35,7 +35,8 @@ Triplets.prototype.isDesired = function (triplet) { }; Triplets.prototype.toArray = function () { - var triplet, triplets = []; + var triplet = []; + var triplets = []; for (var a = this.min; a < this.max - 1; a++) { for (var b = a + 1; b < this.max; b++) { for (var c = b + 1; c <= this.max; c++) { diff --git a/exercises/queen-attack/README.md b/exercises/queen-attack/README.md index 7c311f4f..f9c6c5bf 100644 --- a/exercises/queen-attack/README.md +++ b/exercises/queen-attack/README.md @@ -11,7 +11,7 @@ A chessboard can be represented by an 8 by 8 array. So if you're told the white queen is at (2, 3) and the black queen at (5, 6), then you'd know you've got a set-up like so: -```plain +```text _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ W _ _ _ _ @@ -28,26 +28,29 @@ share a diagonal. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js - -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine queen-attack.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/queen-attack/example.js b/exercises/queen-attack/example.js index 50016f39..ebe07a5d 100644 --- a/exercises/queen-attack/example.js +++ b/exercises/queen-attack/example.js @@ -1,12 +1,11 @@ 'use strict'; -module.exports = function (options) { - if (options === undefined) { - options = { white: [0, 3], black: [7, 3] }; - } + +module.exports = function (passedInOptions) { + var options = passedInOptions || {white: [0, 3], black: [7, 3]}; if (options.white[0] === options.black[0] && options.white[1] === options.black[1]) { - throw 'Queens cannot share the same space'; + throw String('Queens cannot share the same space'); } this.white = options.white; @@ -61,3 +60,4 @@ module.exports = function (options) { return this.boardRepresentation(); }; }; + diff --git a/exercises/queen-attack/queen-attack.spec.js b/exercises/queen-attack/queen-attack.spec.js index e51205be..b2d4525f 100644 --- a/exercises/queen-attack/queen-attack.spec.js +++ b/exercises/queen-attack/queen-attack.spec.js @@ -18,6 +18,8 @@ describe('Queens', function () { try { var queens = new Queens(positioning); + expect(queens.white).toEqual([2, 4]); + expect(queens.black).toEqual([2, 4]); } catch (error) { expect(error).toEqual('Queens cannot share the same space'); } @@ -26,15 +28,15 @@ describe('Queens', function () { xit('toString representation', function () { var positioning = {white: [2, 4], black: [6, 6]}; var queens = new Queens(positioning); - var board = '_ _ _ _ _ _ _ _\n\ -_ _ _ _ _ _ _ _\n\ -_ _ _ _ W _ _ _\n\ -_ _ _ _ _ _ _ _\n\ -_ _ _ _ _ _ _ _\n\ -_ _ _ _ _ _ _ _\n\ -_ _ _ _ _ _ B _\n\ -_ _ _ _ _ _ _ _\n\ -'; + var board = '_ _ _ _ _ _ _ _\n' + +'_ _ _ _ _ _ _ _\n' + +'_ _ _ _ W _ _ _\n' + +'_ _ _ _ _ _ _ _\n' + +'_ _ _ _ _ _ _ _\n' + +'_ _ _ _ _ _ _ _\n' + +'_ _ _ _ _ _ B _\n' + +'_ _ _ _ _ _ _ _\n' +; expect(queens.toString()).toEqual(board); }); diff --git a/exercises/raindrops/README.md b/exercises/raindrops/README.md index 21754775..541b58df 100644 --- a/exercises/raindrops/README.md +++ b/exercises/raindrops/README.md @@ -19,26 +19,29 @@ Convert a number to a string, the contents of which depend on the number's facto ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine raindrops.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/rational-numbers/README.md b/exercises/rational-numbers/README.md new file mode 100644 index 00000000..12cb067b --- /dev/null +++ b/exercises/rational-numbers/README.md @@ -0,0 +1,62 @@ +# Rational Numbers + +A rational number is defined as the quotient of two integers `a` and `b`, called the numerator and denominator, respectively, where `b != 0`. + +The absolute value `|r|` of the rational number `r = a/b` is equal to `|a|/|b|`. + +The sum of two rational numbers `r1 = a1/b1` and `r2 = a2/b2` is `r1 + r2 = a1/b1 + a2/b2 = (a1 * b2 + a2 * b1) / (b1 * b2)`. + +The difference of two rational numbers `r1 = a1/b1` and `r2 = a2/b2` is `r1 - r2 = a1/b1 - a2/b2 = (a1 * b2 - a2 * b1) / (b1 * b2)`. + +The product (multiplication) of two rational numbers `r1 = a1/b1` and `r2 = a2/b2` is `r1 * r2 = (a1 * a2) / (b1 * b2)`. + +Dividing a rational number `r1 = a1/b1` by another `r2 = a2/b2` is `r1 / r2 = (a1 * b2) / (a2 * b1)` if `a2 * b1` is not zero. + +Exponentiation of a rational number `r = a/b` to a non-negative integer power `n` is `r^n = (a^n)/(b^n)`. + +Exponentiation of a rational number `r = a/b` to a negative integer power `n` is `r^n = (b^m)/(a^m)`, where `m = |n|`. + +Exponentiation of a rational number `r = a/b` to a real (floating-point) number `x` is the quotient `(a^x)/(b^x)`, which is a real number. + +Exponentiation of a real number `x` to a rational number `r = a/b` is `x^(a/b) = root(x^a, b)`, where `root(p, q)` is the `q`th root of `p`. + +Implement the following operations: + - addition, subtraction, multiplication and division of two rational numbers, + - absolute value, exponentiation of a given rational number to an integer power, exponentiation of a given rational number to a real (floating-point) power, exponentiation of a real number to a rational number. + +Your implementation of rational numbers should always be reduced to lowest terms. For example, `4/4` should reduce to `1/1`, `30/60` should reduce to `1/2`, `12/8` should reduce to `3/2`, etc. To reduce a rational number `r = a/b`, divide `a` and `b` by the greatest common divisor (gcd) of `a` and `b`. So, for example, `gcd(12, 8) = 4`, so `r = 12/8` can be reduced to `(12/4)/(8/4) = 3/2`. + +Assume that the programming language you are using does not have an implementation of rational numbers. + +## Setup + +Go through the setup instructions for JavaScript to install the + necessary dependencies: + +http://exercism.io/languages/javascript/installation + +## Running the test suite + +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: + +```sh +npm install -g jasmine +``` + +Run the test suite from the exercise directory with: + +```sh +jasmine rational-numbers.spec.js +``` + +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. + +## Source + +Wikipedia [https://en.wikipedia.org/wiki/Rational_number](https://en.wikipedia.org/wiki/Rational_number) + +## 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/rational-numbers/example.js b/exercises/rational-numbers/example.js new file mode 100644 index 00000000..cd95bdc1 --- /dev/null +++ b/exercises/rational-numbers/example.js @@ -0,0 +1,69 @@ +function Rational(numerator, denominator) { + if (denominator === 0) {throw new Error('Denominator must not be zero.');} + + this.numerator = numerator; + this.denominator = denominator; + + this.reduce(); + this.ensureSignInNumerator(); +} + +Rational.prototype.add = function (that) { + var commonDenominator = this.denominator * that.denominator; + return new Rational(this.numerator * that.denominator + that.numerator * this.denominator, commonDenominator); +}; + +Rational.prototype.sub = function (that) { + var commonDenominator = this.denominator * that.denominator; + return new Rational(this.numerator * that.denominator - that.numerator * this.denominator, commonDenominator); +}; + +Rational.prototype.mul = function (that) { + return new Rational(this.numerator * that.numerator, this.denominator * that.denominator); +}; + +Rational.prototype.div = function (that) { + return new Rational(this.numerator * that.denominator, this.denominator * that.numerator); +}; + +Rational.prototype.abs = function () { + return new Rational(Math.abs(this.numerator), Math.abs(this.denominator)); +}; + +Rational.prototype.exprational = function (n) { + return new Rational(Math.pow(this.numerator, n), Math.pow(this.denominator, n)); +}; + +Rational.prototype.expreal = function (base) { + return Math.pow(10.0, Math.log10(Math.pow(base, this.numerator)) / this.denominator); +}; + +Rational.prototype.reduce = function () { + var commonDivisor = this.gcd(this.numerator, this.denominator); + + this.numerator /= commonDivisor; + this.denominator /= commonDivisor; + this.ensureSignInNumerator(); + + return this; +}; + +Rational.prototype.gcd = function (a, b) { + var localA = a; + var localB = b; + while (localB !== 0) { + var t = localB; + localB = localA % localB; + localA = t; + } + return localA; +}; + +Rational.prototype.ensureSignInNumerator = function () { + if (this.denominator < 0) { + this.denominator = -this.denominator; + this.numerator = -this.numerator; + } +}; + +module.exports = Rational; diff --git a/exercises/rational-numbers/rational-numbers.spec.js b/exercises/rational-numbers/rational-numbers.spec.js new file mode 100644 index 00000000..b11c7ed3 --- /dev/null +++ b/exercises/rational-numbers/rational-numbers.spec.js @@ -0,0 +1,197 @@ +var Rational = require('./rational-numbers'); + +describe('Addition', function () { + it('Add two positive rational numbers', function () { + var expected = new Rational(7, 6); + expect(new Rational(1, 2).add(new Rational(2, 3))).toEqual(expected); + }); + + xit('Add a positive rational number and a negative rational number', function () { + var expected = new Rational(-1, 6); + expect(new Rational(1, 2).add(new Rational(-2, 3))).toEqual(expected); + }); + + xit('Add two negative rational numbers', function () { + var expected = new Rational(-7, 6); + expect(new Rational(-1, 2).add(new Rational(-2, 3))).toEqual(expected); + }); + + xit('Add a rational number to its additive inverse', function () { + var expected = new Rational(0, 1); + expect(new Rational(1, 2).add(new Rational(-1, 2))).toEqual(expected); + }); +}); + +describe('Subtraction', function () { + xit('Subtract two positive rational numbers', function () { + var expected = new Rational(-1, 6); + expect(new Rational(1, 2).sub(new Rational(2, 3))).toEqual(expected); + }); + + xit('Subtract a positive rational number and a negative rational number', function () { + var expected = new Rational(7, 6); + expect(new Rational(1, 2).sub(new Rational(-2, 3))).toEqual(expected); + }); + + xit('Subtract two negative rational numbers', function () { + var expected = new Rational(1, 6); + expect(new Rational(-1, 2).sub(new Rational(-2, 3))).toEqual(expected); + }); + + xit('Subtract a rational number from itself', function () { + var expected = new Rational(0, 1); + expect(new Rational(1, 2).sub(new Rational(1, 2))).toEqual(expected); + }); +}); + +describe('Multiplication', function () { + xit('Multiply two positive rational numbers', function () { + var expected = new Rational(1, 3); + expect(new Rational(1, 2).mul(new Rational(2, 3))).toEqual(expected); + }); + + xit('Multiply a negative rational number by a positive rational number', function () { + var expected = new Rational(-1, 3); + expect(new Rational(-1, 2).mul(new Rational(2, 3))).toEqual(expected); + }); + + xit('Multiply two negative rational numbers', function () { + var expected = new Rational(1, 3); + expect(new Rational(-1, 2).mul(new Rational(-2, 3))).toEqual(expected); + }); + + xit('Multiply a rational number by its reciprocal', function () { + var expected = new Rational(1, 1); + expect(new Rational(1, 2).mul(new Rational(2, 1))).toEqual(expected); + }); + + xit('Multiply a rational number by 1', function () { + var expected = new Rational(1, 2); + expect(new Rational(1, 2).mul(new Rational(1, 1))).toEqual(expected); + }); + + xit('Multiply a rational number by 0', function () { + var expected = new Rational(0, 1); + expect(new Rational(1, 2).mul(new Rational(0, 1))).toEqual(expected); + }); +}); + +describe('Division', function () { + xit('Divide two positive rational numbers', function () { + var expected = new Rational(3, 4); + expect(new Rational(1, 2).div(new Rational(2, 3))).toEqual(expected); + }); + + xit('Divide a positive rational number by a negative rational number', function () { + var expected = new Rational(-3, 4); + expect(new Rational(1, 2).div(new Rational(-2, 3))).toEqual(expected); + }); + + xit('Divide two negative rational numbers', function () { + var expected = new Rational(3, 4); + expect(new Rational(-1, 2).div(new Rational(-2, 3))).toEqual(expected); + }); + + xit('Divide a rational number by 1', function () { + var expected = new Rational(1, 2); + expect(new Rational(1, 2).div(new Rational(1, 1))).toEqual(expected); + }); +}); + +describe('Absolute value', function () { + xit('Absolute value of a positive rational number', function () { + var expected = new Rational(1, 2); + expect(new Rational(1, 2).abs()).toEqual(expected); + }); + + xit('Absolute value of a negative rational number', function () { + var expected = new Rational(1, 2); + expect(new Rational(-1, 2).abs()).toEqual(expected); + }); + + xit('Absolute value of zero', function () { + var expected = new Rational(0, 1); + expect(new Rational(0, 1).abs()).toEqual(expected); + }); +}); + +describe('Exponentiation of a rational number', function () { + xit('Raise a positive rational number to a positive integer power', function () { + var expected = new Rational(1, 8); + expect(new Rational(1, 2).exprational(3)).toEqual(expected); + }); + + xit('Raise a negative rational number to a positive integer power', function () { + var expected = new Rational(-1, 8); + expect(new Rational(-1, 2).exprational(3)).toEqual(expected); + }); + + xit('Raise zero to an integer power', function () { + var expected = new Rational(0, 1); + expect(new Rational(0, 1).exprational(5)).toEqual(expected); + }); + + xit('Raise one to an integer power', function () { + var expected = new Rational(1, 1); + expect(new Rational(1, 1).exprational(4)).toEqual(expected); + }); + + xit('Raise a positive rational number to the power of zero', function () { + var expected = new Rational(1, 1); + expect(new Rational(1, 2).exprational(0)).toEqual(expected); + }); + + xit('Raise a negative rational number to the power of zero', function () { + var expected = new Rational(1, 1); + expect(new Rational(-1, 2).exprational(0)).toEqual(expected); + }); +}); + +describe('Exponentiation of a real number to a rational number', function () { + xit('Raise a real number to a positive rational number', function () { + var expected = 16.0; + expect(new Rational(4, 3).expreal(8)).toEqual(expected); + }); + + xit('Raise a real number to a negative rational number', function () { + var expected = 0.3333333333333333; + expect(new Rational(-1, 2).expreal(9)).toEqual(expected); + }); + + xit('Raise a real number to a zero rational number', function () { + var expected = 1.0; + expect(new Rational(0, 1).expreal(2)).toEqual(expected); + }); +}); + +describe('Reduction to lowest terms', function () { + xit('Reduce a positive rational number to lowest terms', function () { + var expected = new Rational(1, 2); + expect(new Rational(2, 4).reduce()).toEqual(expected); + }); + + xit('Reduce a negative rational number to lowest terms', function () { + var expected = new Rational(-2, 3); + expect(new Rational(-4, 6).reduce()).toEqual(expected); + }); + + xit('Reduce a rational number with a negative denominator to lowest terms', function () { + var expected = new Rational(-1, 3); + expect(new Rational(3, -9).reduce()).toEqual(expected); + }); + + xit('Reduce zero to lowest terms', function () { + var expected = new Rational(0, 1); + expect(new Rational(0, 6).reduce()).toEqual(expected); + }); + + xit('Reduce an integer to lowest terms', function () { + var expected = new Rational(-2, 1); + expect(new Rational(-14, 7).reduce()).toEqual(expected); + }); + + xit('Reduce one to lowest terms', function () { + var expected = new Rational(1, 1); + expect(new Rational(13, 13).reduce()).toEqual(expected); + }); +}); diff --git a/exercises/rectangles/README.md b/exercises/rectangles/README.md new file mode 100644 index 00000000..362ed98c --- /dev/null +++ b/exercises/rectangles/README.md @@ -0,0 +1,91 @@ +# Rectangles + +Count the rectangles in an ASCII diagram like the one below. + +```text + +--+ + ++ | ++-++--+ +| | | ++--+--+ +``` + +The above diagram contains 6 rectangles: + +```text + + ++-----+ +| | ++-----+ +``` + +```text + +--+ + | | + | | + | | + +--+ +``` + +```text + +--+ + | | + +--+ + + +``` + +```text + + + +--+ + | | + +--+ +``` + +```text + + ++--+ +| | ++--+ +``` + +```text + + ++ + ++ + + +``` + +You may assume that the input is always a proper rectangle (i.e. the length of +every line equals the length of the first line). + +## 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 Hello World exercise: + + jasmine hello-world.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`. + + +## 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/rectangles/example.js b/exercises/rectangles/example.js new file mode 100644 index 00000000..f9cb52c3 --- /dev/null +++ b/exercises/rectangles/example.js @@ -0,0 +1,66 @@ +var GLYPH = { corner: '+', edgeV: '|', edgeH: '-' }; + +var Vertex = function () { + this.right = []; + this.down = []; +}; + +// number of rectangles with given top left corner +Vertex.prototype.findRectangles = function () { + var corners = []; + var rectangles = 0; + + this.right.forEach(function (topLeft) { + topLeft.down.forEach(function (bottomRight) { + corners.push(bottomRight); + }); + }); + this.down.forEach(function (bottomLeft) { + bottomLeft.right.forEach(function (bottomRight) { + if (corners.indexOf(bottomRight) >= 0) { + rectangles++; + } + }); + }); + return rectangles; +}; + +// finds connected corners right and down from every corner +var toVertices = function (grid) { + var vertices = []; + grid.forEach(function (row, y) { + row.forEach(function (cell, x) { + if (cell === GLYPH.corner) { + var newVert = new Vertex(); + var side; + + vertices.push(newVert); + grid[y][x] = newVert; // replace glyph with the vertex + for (var u = y - 1; u >= 0; u--) { // search *up* along the side + side = grid[u][x]; + if (side instanceof Vertex) side.down.push(newVert); + else if (side !== GLYPH.edgeV) break; + } + for (var l = x - 1; l >= 0; l--) { // search *left* along the side + side = grid[y][l]; + if (side instanceof Vertex) side.right.push(newVert); + else if (side !== GLYPH.edgeH) break; + } + } + }); + }); + return vertices; +}; + +var rectangles = function (input) { + var grid; + var corners; + + grid = input.map(function (row) { return row.split(''); }); + corners = toVertices(grid); + return corners.reduce(function (total, vert) { + return total + vert.findRectangles(); + }, 0); +}; + +module.exports = rectangles; diff --git a/exercises/rectangles/rectangles.spec.js b/exercises/rectangles/rectangles.spec.js new file mode 100644 index 00000000..af89e07d --- /dev/null +++ b/exercises/rectangles/rectangles.spec.js @@ -0,0 +1,108 @@ +var rectangles = require('./rectangles'); + +describe('Rectangles', function () { + it('no rows', function () { + expect(rectangles([])).toBe(0); + }); + + xit('no columns', function () { + expect(rectangles([''])).toBe(0); + }); + + xit('no rectangles', function () { + expect(rectangles([' '])).toBe(0); + }); + + xit('one rectangle', function () { + var input = [ + '+-+', + '| |', + '+-+']; + expect(rectangles(input)).toBe(1); + }); + + xit('two rectangles without shared parts', function () { + var input = [ + ' +-+', + ' | |', + '+-+-+', + '| | ', + '+-+ ']; + expect(rectangles(input)).toBe(2); + }); + + xit('five rectangles with shared parts', function () { + var input = [ + ' +-+', + ' | |', + '+-+-+', + '| | |', + '+-+-+']; + expect(rectangles(input)).toBe(5); + }); + + xit('rectangle of height 1 is counted', function () { + var input = [ + '+--+', + '+--+']; + expect(rectangles(input)).toBe(1); + }); + + xit('rectangle of width 1 is counted', function () { + var input = [ + '++', + '||', + '++']; + expect(rectangles(input)).toBe(1); + }); + + xit('1x1 square is counted', function () { + var input = [ + '++', + '++']; + expect(rectangles(input)).toBe(1); + }); + + xit('only complete rectangles are counted', function () { + var input = [ + ' +-+', + ' |', + '+-+-+', + '| | -', + '+-+-+']; + expect(rectangles(input)).toBe(1); + }); + + xit('rectangles can be of different sizes', function () { + var input = [ + '+------+----+', + '| | |', + '+---+--+ |', + '| | |', + '+---+-------+']; + expect(rectangles(input)).toBe(3); + }); + + xit('corner is required for a rectangle to be complete', function () { + var input = [ + '+------+----+', + '| | |', + '+------+ |', + '| | |', + '+---+-------+']; + expect(rectangles(input)).toBe(2); + }); + + xit('large input with many rectangles', function () { + var input = [ + '+---+--+----+', + '| +--+----+', + '+---+--+ |', + '| +--+----+', + '+---+--+--+-+', + '+---+--+--+-+', + '+------+ | |', + ' +-+']; + expect(rectangles(input)).toBe(60); + }); +}); diff --git a/exercises/reverse-string/README.md b/exercises/reverse-string/README.md new file mode 100644 index 00000000..f9edf6c5 --- /dev/null +++ b/exercises/reverse-string/README.md @@ -0,0 +1,40 @@ +# Reverse String + +Reverse a 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/installation + +## Running the test suite + +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: + +```sh +npm install -g jasmine +``` + +Run the test suite from the exercise directory with: + +```sh +jasmine reverse-string.spec.js +``` + +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. + +## Source + +Introductory challenge to reverse an input string [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/example.js b/exercises/reverse-string/example.js new file mode 100644 index 00000000..b19b8d8d --- /dev/null +++ b/exercises/reverse-string/example.js @@ -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; diff --git a/exercises/reverse-string/reverse-string.spec.js b/exercises/reverse-string/reverse-string.spec.js new file mode 100644 index 00000000..c6d6327c --- /dev/null +++ b/exercises/reverse-string/reverse-string.spec.js @@ -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); + }); +}); diff --git a/exercises/rna-transcription/README.md b/exercises/rna-transcription/README.md index 53944760..ab942a69 100644 --- a/exercises/rna-transcription/README.md +++ b/exercises/rna-transcription/README.md @@ -1,4 +1,4 @@ -# Rna Transcription +# RNA Transcription Given a DNA strand, return its RNA complement (per RNA transcription). @@ -20,26 +20,29 @@ each nucleotide with its complement: ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine rna-transcription.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/robot-name/README.md b/exercises/robot-name/README.md index e679b1ad..7b875976 100644 --- a/exercises/robot-name/README.md +++ b/exercises/robot-name/README.md @@ -17,26 +17,29 @@ every existing robot has a unique name. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine robot-name.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/robot-name/robot-name.spec.js b/exercises/robot-name/robot-name.spec.js index 810c92ab..f9b244f5 100644 --- a/exercises/robot-name/robot-name.spec.js +++ b/exercises/robot-name/robot-name.spec.js @@ -35,9 +35,9 @@ describe('Robot', function () { }); xit('should set a unique name after reset', function () { - var i, - numResets = 10000, - usedNames = {}; + var i; + var numResets = 10000; + var usedNames = {}; usedNames[robot.name] = true; @@ -49,11 +49,11 @@ describe('Robot', function () { expect(Object.keys(usedNames).length).toEqual(numResets + 1); }); - // This test is optional. + // This test is optional. xit('there can be lots of robots with different names each', function () { - var i, - numRobots = 10000, - usedNames = {}; + var i; + var numRobots = 10000; + var usedNames = {}; for (i = 0; i < numRobots; i++) { var newRobot = new Robot(); diff --git a/exercises/robot-simulator/README.md b/exercises/robot-simulator/README.md index cf8731bf..796b4e6e 100644 --- a/exercises/robot-simulator/README.md +++ b/exercises/robot-simulator/README.md @@ -29,26 +29,29 @@ direction it is pointing. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine robot-simulator.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/robot-simulator/example.js b/exercises/robot-simulator/example.js index 769134f5..96bb5c90 100644 --- a/exercises/robot-simulator/example.js +++ b/exercises/robot-simulator/example.js @@ -1,87 +1,85 @@ -var Robot = (function () { - 'use strict'; +'use strict'; - var VALID_DIRECTIONS = ['north', 'east', 'south', 'west']; - var INSTRUCTION_KEYS = { - A: 'advance', - L: 'turnLeft', - R: 'turnRight' - }; +var VALID_DIRECTIONS = ['north', 'east', 'south', 'west']; +var INSTRUCTION_KEYS = { + A: 'advance', + L: 'turnLeft', + R: 'turnRight' +}; - function Robot() { - this.coordinates = [0, 0]; - this.bearing = 'north'; - } - - Robot.prototype.at = function (x, y) { - this.coordinates = [x, y]; - }; +function Robot() { + this.coordinates = [0, 0]; + this.bearing = 'north'; +} - Robot.prototype.orient = function (direction) { - if (VALID_DIRECTIONS.indexOf(direction) === -1) { - throw new Error('Invalid Robot Bearing'); - } +Robot.prototype.at = function (x, y) { + this.coordinates = [x, y]; +}; - this.bearing = direction; - }; +Robot.prototype.orient = function (direction) { + if (VALID_DIRECTIONS.indexOf(direction) === -1) { + throw new Error('Invalid Robot Bearing'); + } - Robot.prototype.advance = function () { - switch (this.bearing) { - case 'north': - this.coordinates[1]++; - break; - case 'east': - this.coordinates[0]++; - break; - case 'south': - this.coordinates[1]--; - break; - case 'west': - this.coordinates[0]--; - break; - } - }; + this.bearing = direction; +}; - Robot.prototype.turnLeft = function () { - var directionPosition = VALID_DIRECTIONS.indexOf(this.bearing); +Robot.prototype.advance = function () { + switch (this.bearing) { + case 'north': + this.coordinates[1]++; + break; + case 'east': + this.coordinates[0]++; + break; + case 'south': + this.coordinates[1]--; + break; + case 'west': + this.coordinates[0]--; + break; + default: + break; + } +}; - if (directionPosition > 0) { - this.orient(VALID_DIRECTIONS[--directionPosition]); - } else { - this.orient(VALID_DIRECTIONS[VALID_DIRECTIONS.length - 1]); - } - }; +Robot.prototype.turnLeft = function () { + var directionPosition = VALID_DIRECTIONS.indexOf(this.bearing); - Robot.prototype.turnRight = function () { - var directionPosition = VALID_DIRECTIONS.indexOf(this.bearing); + if (directionPosition > 0) { + this.orient(VALID_DIRECTIONS[--directionPosition]); + } else { + this.orient(VALID_DIRECTIONS[VALID_DIRECTIONS.length - 1]); + } +}; - if (directionPosition < (VALID_DIRECTIONS.length - 1)) { - this.orient(VALID_DIRECTIONS[++directionPosition]); - } else { - this.orient(VALID_DIRECTIONS[0]); - } - }; +Robot.prototype.turnRight = function () { + var directionPosition = VALID_DIRECTIONS.indexOf(this.bearing); - Robot.prototype.instructions = function (instructionKeys) { - return instructionKeys.split('') - .map(function (key) { - return INSTRUCTION_KEYS[key]; - }); - }; + if (directionPosition < (VALID_DIRECTIONS.length - 1)) { + this.orient(VALID_DIRECTIONS[++directionPosition]); + } else { + this.orient(VALID_DIRECTIONS[0]); + } +}; - Robot.prototype.place = function (args) { - this.coordinates = [args.x, args.y]; - this.bearing = args.direction; - }; +Robot.prototype.instructions = function (instructionKeys) { + return instructionKeys.split('') + .map(function (key) { + return INSTRUCTION_KEYS[key]; + }); +}; - Robot.prototype.evaluate = function (instructionKeys) { - this.instructions(instructionKeys) - .forEach(function (instruction) { - this[instruction](); - }, this); - }; +Robot.prototype.place = function (args) { + this.coordinates = [args.x, args.y]; + this.bearing = args.direction; +}; - return Robot; -})(); +Robot.prototype.evaluate = function (instructionKeys) { + this.instructions(instructionKeys) + .forEach(function (instruction) { + this[instruction](); + }, this); +}; module.exports = Robot; diff --git a/exercises/roman-numerals/README.md b/exercises/roman-numerals/README.md index 77174297..ab2f8dc0 100644 --- a/exercises/roman-numerals/README.md +++ b/exercises/roman-numerals/README.md @@ -14,7 +14,7 @@ The Romans wrote numbers using letters - I, V, X, L, C, D, M. (notice these letters have lots of straight lines and are hence easy to hack into stone tablets). -``` +```text 1 => I 10 => X 7 => VII @@ -44,26 +44,29 @@ See also: http://www.novaroma.org/via_romana/numbers.html ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine roman-numerals.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/roman-numerals/example.js b/exercises/roman-numerals/example.js index 40e8ddf0..a39d19cc 100644 --- a/exercises/roman-numerals/example.js +++ b/exercises/roman-numerals/example.js @@ -2,6 +2,7 @@ module.exports = function (number) { var result = ''; + var numbers = number; var mappings = [ {arabic: 1000, roman: 'M'}, {arabic: 900, roman: 'CM'}, @@ -20,9 +21,9 @@ module.exports = function (number) { for (var i = 0; i < mappings.length; i++) { var mapping = mappings[i]; - while (number >= mapping.arabic) { + while (numbers >= mapping.arabic) { result = result + mapping.roman; - number = number - mapping.arabic; + numbers = numbers - mapping.arabic; } } diff --git a/exercises/rotational-cipher/README.md b/exercises/rotational-cipher/README.md new file mode 100644 index 00000000..01384ca3 --- /dev/null +++ b/exercises/rotational-cipher/README.md @@ -0,0 +1,64 @@ +# Rotational Cipher + +Create an implementation of the rotational cipher, also sometimes called the Caesar cipher. + +The Caesar cipher is a simple shift cipher that relies on +transposing all the letters in the alphabet using an integer key +between `0` and `26`. Using a key of `0` or `26` will always yield +the same output due to modular arithmetic. The letter is shifted +for as many values as the value of the key. + +The general notation for rotational ciphers is `ROT + `. +The most commonly used rotational cipher is `ROT13`. + +A `ROT13` on the Latin alphabet would be as follows: + +```text +Plain: abcdefghijklmnopqrstuvwxyz +Cipher: nopqrstuvwxyzabcdefghijklm +``` + +It is stronger than the Atbash cipher because it has 27 possible keys, and 25 usable keys. + +Ciphertext is written out in the same formatting as the input including spaces and punctuation. + +## Examples + +- ROT5 `omg` gives `trl` +- ROT0 `c` gives `c` +- ROT26 `Cool` gives `Cool` +- ROT13 `The quick brown fox jumps over the lazy dog.` gives `Gur dhvpx oebja sbk whzcf bire gur ynml qbt.` +- ROT13 `Gur dhvpx oebja sbk whzcf bire gur ynml qbt.` gives `The quick brown fox jumps over the lazy dog.` + +## Setup + +Go through the setup instructions for JavaScript to install the + necessary dependencies: + +http://exercism.io/languages/javascript/installation + +## Running the test suite + +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: + +```sh +npm install -g jasmine +``` + +Run the test suite from the exercise directory with: + +```sh +jasmine rotational-cipher.spec.js +``` + +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. + +## Source + +Wikipedia [https://en.wikipedia.org/wiki/Caesar_cipher](https://en.wikipedia.org/wiki/Caesar_cipher) + +## 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/rotational-cipher/example.js b/exercises/rotational-cipher/example.js new file mode 100644 index 00000000..fa3e7baa --- /dev/null +++ b/exercises/rotational-cipher/example.js @@ -0,0 +1,24 @@ +var RotationalCipher = function () {}; + +RotationalCipher.prototype.rotate = function (text, shiftKey) { + if (text.length === 1) { + if (text.charCodeAt(0) >= 97 && text.charCodeAt(0) <= 122) return this.rotateLowerCase(text, shiftKey); + if (text.charCodeAt(0) >= 65 && text.charCodeAt(0) <= 90) return this.rotateUpperCase(text, shiftKey); + return text; + } + return this.rotate(text.charAt(0), shiftKey) + this.rotate(text.slice(1), shiftKey); +}; + +RotationalCipher.prototype.rotateLowerCase = function (letter, shiftKey) { + var rotatedLowerCase = String.fromCharCode(letter.charCodeAt(0) + shiftKey); + if (rotatedLowerCase.charCodeAt(0) > 122) rotatedLowerCase = String.fromCharCode(rotatedLowerCase.charCodeAt(0) - 26); + return rotatedLowerCase; +}; + +RotationalCipher.prototype.rotateUpperCase = function (letter, shiftKey) { + var rotatedUpperCase = String.fromCharCode(letter.charCodeAt(0) + shiftKey); + if (rotatedUpperCase.charCodeAt(0) > 90) rotatedUpperCase = String.fromCharCode(rotatedUpperCase.charCodeAt(0) - 26); + return rotatedUpperCase; +}; + +module.exports = RotationalCipher; diff --git a/exercises/rotational-cipher/rotational-cipher.spec.js b/exercises/rotational-cipher/rotational-cipher.spec.js new file mode 100644 index 00000000..5e6f864d --- /dev/null +++ b/exercises/rotational-cipher/rotational-cipher.spec.js @@ -0,0 +1,55 @@ +var RotationalCipher = require('./rotational-cipher'); + +describe('RotationalCipher', function () { + var rotationalCipher = new RotationalCipher(); + + it('rotate a by 0, same output as input', function () { + var expected = 'a'; + expect(rotationalCipher.rotate('a', 0)).toEqual(expected); + }); + + xit('rotate a by 1', function () { + var expected = 'b'; + expect(rotationalCipher.rotate('a', 1)).toEqual(expected); + }); + + xit('rotate a by 26, same output as input', function () { + var expected = 'a'; + expect(rotationalCipher.rotate('a', 26)).toEqual(expected); + }); + + xit('rotate m by 13', function () { + var expected = 'z'; + expect(rotationalCipher.rotate('m', 13)).toEqual(expected); + }); + + xit('rotate n by 13 with wrap around alphabet', function () { + var expected = 'a'; + expect(rotationalCipher.rotate('n', 13)).toEqual(expected); + }); + + xit('rotate capital letters', function () { + var expected = 'TRL'; + expect(rotationalCipher.rotate('OMG', 5)).toEqual(expected); + }); + + xit('rotate spaces', function () { + var expected = 'T R L'; + expect(rotationalCipher.rotate('O M G', 5)).toEqual(expected); + }); + + xit('rotate numbers', function () { + var expected = 'Xiwxmrk 1 2 3 xiwxmrk'; + expect(rotationalCipher.rotate('Testing 1 2 3 testing', 4)).toEqual(expected); + }); + + xit('rotate punctuation', function () { + var expected = 'Gzo\'n zvo, Bmviyhv!'; + expect(rotationalCipher.rotate('Let\'s eat, Grandma!', 21)).toEqual(expected); + }); + + xit('rotate all letters', function () { + var expected = 'Gur dhvpx oebja sbk whzcf bire gur ynml qbt.'; + expect(rotationalCipher.rotate('The quick brown fox jumps over the lazy dog.', 13)).toEqual(expected); + }); +}); diff --git a/exercises/run-length-encoding/README.md b/exercises/run-length-encoding/README.md index e91fd159..e4499e71 100644 --- a/exercises/run-length-encoding/README.md +++ b/exercises/run-length-encoding/README.md @@ -7,44 +7,47 @@ Run-length encoding (RLE) is a simple form of data compression, where runs For example we can represent the original 53 characters with only 13. -``` +```text "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB" -> "12WB12W3B24WB" ``` RLE allows the original data to be perfectly reconstructed from the compressed data, which makes it a lossless data compression. -``` +```text "AABCCCDEEEE" -> "2AB3CD4E" -> "AABCCCDEEEE" ``` For simplicity, you can assume that the unencoded string will only contain -the letters A through Z (either lower or upper case) and whitespace. This way -data to be encoded will never contain any numbers and numbers inside data to +the letters A through Z (either lower or upper case) and whitespace. This way +data to be encoded will never contain any numbers and numbers inside data to be decoded always represent the count for the following character. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine run-length-encoding.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/saddle-points/README.md b/exercises/saddle-points/README.md index 24a59c28..aa61f4cd 100644 --- a/exercises/saddle-points/README.md +++ b/exercises/saddle-points/README.md @@ -4,7 +4,7 @@ Detect saddle points in a matrix. So say you have a matrix like so: -```plain +```text 0 1 2 |--------- 0 | 9 8 7 @@ -15,7 +15,7 @@ So say you have a matrix like so: It has a saddle point at (1, 0). It's called a "saddle point" because it is greater than or equal to -every element in its row and the less than or equal to every element in +every element in its row and less than or equal to every element in its column. A matrix may have zero or more saddle points. @@ -28,26 +28,29 @@ but the tests for this exercise follow the above unambiguous definition. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js - -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine saddle-points.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/saddle-points/example.js b/exercises/saddle-points/example.js index 81217e7c..ac1cde4f 100644 --- a/exercises/saddle-points/example.js +++ b/exercises/saddle-points/example.js @@ -1,78 +1,57 @@ 'use strict'; -function toInt(s) { - return parseInt(s, 10); -} - module.exports = function Matrix(matrix) { - this.rows = []; - this.columns = []; - - var rows = matrix.split('\n'); - var i, j, currentRow; - - for (i = 0; i < rows.length; i++) { - currentRow = rows[i].replace(/^\s+|\s+$/g, '').split(' ').map( toInt ); - this.rows.push(currentRow); - } - - for (i = 0; i < this.rows[0].length; i++) { - this.columns.push([]); - } + this.rows = matrix.split('\n').map(function (row) { + return row.split(' ').map(function (val) { return parseInt(val, 10); }); + }); - for (i = 0; i < this.rows.length; i++) { - for (j = 0; j < this.columns.length; j++) { - this.columns[j].push(this.rows[i][j]); - } - } + this.columns = this.rows[0].map(function () { + return []; + }).map(function (column, index) { + return this.rows.map(function (row) { return row[index]; }); + }, this); this.indexesOfMaxValues = function (array) { - var i, currentElement, maxValue, indexes = []; + var maxValue = array.reduce(function (acc, curr) { + return Math.max(acc, curr); + }); - for (i = 0; i < array.length; i++) { - currentElement = array[i]; - if (maxValue === undefined || currentElement > maxValue) { - maxValue = currentElement; - indexes = [i]; - } else if (currentElement === maxValue) { - indexes.push(i); - } - } - - return indexes; + return this.indexsOf(array, maxValue); }; this.indexesOfMinValues = function (array) { - var i, currentElement, minValue, indexes = []; + var minValue = array.reduce(function (acc, curr) { + return Math.min(acc, curr); + }); - for (i = 0; i < array.length; i++) { - currentElement = array[i]; - if (minValue === undefined || currentElement < minValue) { - minValue = currentElement; - indexes = [i]; - } else if (currentElement === minValue) { - indexes.push(i); - } - } + return this.indexsOf(array, minValue); + }; - return indexes; + this.indexsOf = function (array, value) { + return array.map(function (val, index) { + return val === value ? index : null; + }).filter(function (val) { + return val !== null; + }); }; this.calculateSaddlePoints = function (rows, columns) { - var i, j, maxIndexes, minIndexes, currentMaxIndex, saddlePoints = []; + var maxIndexes; + var minIndexes; + var saddlePoints = []; - for (i = 0; i < rows.length; i++) { - maxIndexes = this.indexesOfMaxValues(rows[i]); + rows.forEach(function (row, i) { + maxIndexes = this.indexesOfMaxValues(row); - for (j = 0; j < maxIndexes.length; j++) { - currentMaxIndex = maxIndexes[j]; + maxIndexes.forEach(function (currentMaxIndex) { minIndexes = this.indexesOfMinValues(columns[currentMaxIndex]); if (minIndexes.indexOf(i) >= 0) { saddlePoints.push([i, currentMaxIndex]); } - } - } + }, this); + }, this); + return saddlePoints; }; diff --git a/exercises/say/README.md b/exercises/say/README.md index 7be49a95..bd67005b 100644 --- a/exercises/say/README.md +++ b/exercises/say/README.md @@ -64,26 +64,29 @@ Use _and_ (correctly) when spelling out the number in English: ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine say.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/say/example.js b/exercises/say/example.js index 4a69883b..0b96b824 100644 --- a/exercises/say/example.js +++ b/exercises/say/example.js @@ -41,7 +41,8 @@ var bigNumbers = { }; function bigPart(number) { - var factor, result = ''; + var factor; + var result = ''; for (var bigNumber = 1000000000; bigNumber >= 1000; bigNumber /= 1000) { if (number.current >= bigNumber) { factor = Math.floor(number.current / bigNumber); @@ -58,6 +59,7 @@ function sayDecade(n) { return decades[decade] + '-' + smallNumbers[n - decade]; } } + throw new Error('Number must be between 10 and 99.'); } function twoDigit(n) { @@ -78,7 +80,8 @@ function threeDigit(n) { } exports.inEnglish = function (n) { - var result, number = {current: n}; + var result; + var number = {current: n}; if (n >= 0 && n < 1000000000000) { result = bigPart(number); result += threeDigit(number.current); diff --git a/exercises/scrabble-score/README.md b/exercises/scrabble-score/README.md index b0592bef..59b1d90d 100644 --- a/exercises/scrabble-score/README.md +++ b/exercises/scrabble-score/README.md @@ -6,7 +6,7 @@ Given a word, compute the scrabble score for that word. You'll need these: -```plain +```text Letter Value A, E, I, O, U, L, N, R, S, T 1 D, G 2 @@ -18,6 +18,7 @@ Q, Z 10 ``` ## Examples + "cabbage" should be scored as worth 14 points: - 3 points for C @@ -34,31 +35,35 @@ And to total: - = 14 ## Extensions + - You can play a double or a triple letter. - You can play a double or a triple word. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine scrabble-score.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/scrabble-score/example.js b/exercises/scrabble-score/example.js index 28f08414..be6cd36c 100644 --- a/exercises/scrabble-score/example.js +++ b/exercises/scrabble-score/example.js @@ -14,9 +14,8 @@ function letterScore(letter) { return letterScores[letter] || 0; } -module.exports = function (word) { - word || (word = ''); - word = word.toLowerCase(); +module.exports = function (wrd) { + var word = wrd ? wrd.toLowerCase() : ''; var sum = 0; var idx = -1; diff --git a/exercises/secret-handshake/README.md b/exercises/secret-handshake/README.md index dfdd361c..15e4d426 100644 --- a/exercises/secret-handshake/README.md +++ b/exercises/secret-handshake/README.md @@ -6,7 +6,7 @@ You and your fellow cohort of those in the "know" when it comes to binary decide to come up with a secret "handshake". -``` +```text 1 = wink 10 = double blink 100 = close your eyes @@ -30,30 +30,33 @@ has caused the array to be reversed. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine secret-handshake.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source -Bert, in Mary Poppins [http://www.imdb.com/character/ch0011238/quotes](http://www.imdb.com/character/ch0011238/quotes) +Bert, in Mary Poppins [http://www.imdb.com/title/tt0058331/quotes/qt0437047](http://www.imdb.com/title/tt0058331/quotes/qt0437047) ## 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/secret-handshake/example.js b/exercises/secret-handshake/example.js index 651a8d78..873ccc97 100644 --- a/exercises/secret-handshake/example.js +++ b/exercises/secret-handshake/example.js @@ -12,8 +12,7 @@ function SecretHandshake(handshake) { return this.shakeWith; }; - this.calculateHandshake = function (handshake) { - /* jshint bitwise:false */ + this.calculateHandshake = function () { var shakeWith = []; for (var i = 0; i < handshakeCommands.length; i++) { diff --git a/exercises/secret-handshake/secret-handshake.spec.js b/exercises/secret-handshake/secret-handshake.spec.js index 6c29444a..bf5fc41d 100644 --- a/exercises/secret-handshake/secret-handshake.spec.js +++ b/exercises/secret-handshake/secret-handshake.spec.js @@ -38,7 +38,8 @@ describe('Secret Handshake', function () { xit('text is an invalid secret handshake', function () { expect( function () { - var handshake = new SecretHandshake('piggies'); + /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "[iI]gnored" }]*/ + var ignoredHandshake = new SecretHandshake('piggies'); }).toThrow(new Error('Handshake must be a number')); }); }); diff --git a/exercises/series/README.md b/exercises/series/README.md index 81133429..752330d4 100644 --- a/exercises/series/README.md +++ b/exercises/series/README.md @@ -22,26 +22,29 @@ in the input; the digits need not be *numerically consecutive*. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine series.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/sieve/README.md b/exercises/sieve/README.md index b64850a4..33f66f28 100644 --- a/exercises/sieve/README.md +++ b/exercises/sieve/README.md @@ -29,26 +29,29 @@ correct list of primes. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine sieve.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/sieve/example.js b/exercises/sieve/example.js index 85ad948a..3684753f 100644 --- a/exercises/sieve/example.js +++ b/exercises/sieve/example.js @@ -1,7 +1,8 @@ 'use strict'; function newArrayWithRange(first, last) { - var i, array = []; + var i; + var array = []; for ( i = first; i <= last; i++ ) { array.push(i); } @@ -13,7 +14,9 @@ function indivisibleBy(value) { } function sieve(n) { - var i, prime, possibilities, primes = []; + var prime; + var possibilities; + var primes = []; possibilities = newArrayWithRange(2, n); diff --git a/exercises/simple-cipher/README.md b/exercises/simple-cipher/README.md index 37536369..e0ee4353 100644 --- a/exercises/simple-cipher/README.md +++ b/exercises/simple-cipher/README.md @@ -58,15 +58,13 @@ would get the same thing as the Caesar Cipher. The weakest link in any cipher is the human being. Let's make your substitution cipher a little more fault tolerant by providing a source -of randomness and ensuring that the key is not composed of numbers or -capital letters. +of randomness and ensuring that the key contains only lowercase letters. If someone doesn't submit a key at all, generate a truly random key of -at least 100 characters in length, accessible via Cipher#key (the # -syntax means instance variable) +at least 100 characters in length. -If the key submitted has capital letters or numbers, throw an -ArgumentError with a message to that effect. +If the key submitted is not composed only of lowercase letters, your +solution should handle the error in a language-appropriate way. ## Extensions @@ -85,26 +83,29 @@ on Wikipedia][dh] for one of the first implementations of this scheme. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine simple-cipher.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/simple-cipher/example.js b/exercises/simple-cipher/example.js index b8cc5151..6f0177fb 100644 --- a/exercises/simple-cipher/example.js +++ b/exercises/simple-cipher/example.js @@ -3,8 +3,8 @@ var ALPHABET = 'abcdefghijklmnopqrstuvwxyz'; function randomKey() { - var i, result = ''; - for ( i = 0; i < 100; i++ ) { + var result; + for ( var i = 0; i < 100; i++ ) { result += ALPHABET[randomUpTo(ALPHABET.length)]; } return result; @@ -17,15 +17,13 @@ function randomUpTo(n) { module.exports = function (userDefinedKey) { var key; - function addEncodedCharacter(character, index, array) { - /* jshint validthis:true */ + function addEncodedCharacter(character, index) { var i = ALPHABET.indexOf(character) + ALPHABET.indexOf(key[index % key.length]); if (i >= ALPHABET.length) { i -= ALPHABET.length; } this.push(ALPHABET[i]); } - function addDecodedCharacter(character, index, array) { - /* jshint validthis:true */ + function addDecodedCharacter(character, index) { var i = ALPHABET.indexOf(character) - ALPHABET.indexOf(key[index % key.length]); if (i < 0) { i += ALPHABET.length; } this.push(ALPHABET[i]); diff --git a/exercises/simple-cipher/simple-cipher.spec.js b/exercises/simple-cipher/simple-cipher.spec.js index f3fb2b39..c59c16cf 100644 --- a/exercises/simple-cipher/simple-cipher.spec.js +++ b/exercises/simple-cipher/simple-cipher.spec.js @@ -1,5 +1,15 @@ var Cipher = require('./simple-cipher'); +describe('Random key generation', function () { + xit('generates keys at random', function () { + // Strictly speaking, this is difficult to test with 100% certainty. + // But, if you have a generator that generates 100-character-long + // strings of lowercase letters at random, the odds of two consecutively + // generated keys being identical are astronomically low. + expect(new Cipher().key).not.toEqual(new Cipher().key); + }); +}); + describe('Random key cipher', function () { var cipher = new Cipher(); @@ -7,6 +17,10 @@ describe('Random key cipher', function () { expect(cipher.key).toMatch(/^[a-z]+$/); }); + xit('has a key that is at least 100 characters long', function () { + expect(cipher.key.length).toBeGreaterThanOrEqual(100); + }); + // Here we take advantage of the fact that plaintext of "aaa..." // outputs the key. This is a critical problem with shift ciphers, some // characters will always output the key verbatim. @@ -24,26 +38,30 @@ describe('Random key cipher', function () { }); }); +/* eslint-disable no-new */ + describe('Incorrect key cipher', function () { xit('throws an error with an all caps key', function () { - expect( function () { + expect(function () { new Cipher('ABCDEF'); }).toThrow(new Error('Bad key')); }); xit('throws an error with a numeric key', function () { - expect( function () { + expect(function () { new Cipher('12345'); }).toThrow(new Error('Bad key')); }); xit('throws an error with an empty key', function () { - expect( function () { + expect(function () { new Cipher(''); }).toThrow(new Error('Bad key')); }); }); +/* eslint-enable no-new */ + describe('Substitution cipher', function () { var key = 'abcdefghij'; var cipher = new Cipher(key); diff --git a/exercises/simple-linked-list/README.md b/exercises/simple-linked-list/README.md index f9e7ff91..07e40594 100644 --- a/exercises/simple-linked-list/README.md +++ b/exercises/simple-linked-list/README.md @@ -23,26 +23,29 @@ implement your own abstract data type. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine simple-linked-list.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/simple-linked-list/example.js b/exercises/simple-linked-list/example.js index 6e1f0d05..e8fca85f 100644 --- a/exercises/simple-linked-list/example.js +++ b/exercises/simple-linked-list/example.js @@ -3,11 +3,11 @@ function Element(value, next) { throw new Error('Element is a constructor.'); } - if (value === undefined) { + if (typeof value === 'undefined') { throw new Error('Value required.'); } - if (next !== undefined && !(next instanceof Element)) { + if (typeof next !== 'undefined' && !(next instanceof Element)) { throw new Error('A Element instance as next value is required.'); } @@ -18,7 +18,7 @@ function Element(value, next) { function List() {} List.prototype.push = function (value) { - if (value === undefined) { + if (typeof value === 'undefined') { throw new Error('Argument required.'); } @@ -40,7 +40,7 @@ List.prototype.push = function (value) { }; List.prototype.unshift = function (value) { - if (value === undefined) { + if (typeof value === 'undefined') { throw new Error('Argument required.'); } @@ -65,17 +65,20 @@ List.prototype.pop = function () { return; } - var penultEl, lastEl = this.head; + var penultEl; + var lastEl = this.head; while (lastEl.next) { penultEl = lastEl; lastEl = lastEl.next; } + /* eslint-disable no-undefined */ if (!penultEl) { this.head = undefined; } else { penultEl.next = undefined; } + /* eslint-enable no-undefined */ }; List.prototype.reverse = function () { @@ -83,7 +86,8 @@ List.prototype.reverse = function () { return; } - var current, previous; + var current; + var previous; while (this.head) { current = this.head; this.shift(); diff --git a/exercises/simple-linked-list/simple-linked-list.spec.js b/exercises/simple-linked-list/simple-linked-list.spec.js index 1254743b..75460d35 100644 --- a/exercises/simple-linked-list/simple-linked-list.spec.js +++ b/exercises/simple-linked-list/simple-linked-list.spec.js @@ -16,9 +16,11 @@ describe('simple-linked-list', function () { var el = new Element(1); expect(el).toBeDefined(); + /* eslint-disable new-cap */ expect(function () { - var el = Element(1); + el = Element(1); }).toThrow(); + /* eslint-enable new-cap */ }); xit('requires an argument', function () { @@ -26,7 +28,7 @@ describe('simple-linked-list', function () { expect(el).toBeDefined(); expect(function () { - var el = new Element(); + el = new Element(); }).toThrow(); }); @@ -47,9 +49,9 @@ describe('simple-linked-list', function () { expect(elTwo.next).toBe(elOne); }); + /* eslint-disable no-unused-vars */ xit('requires an instance of Element as next element', function () { expect(function () { - var el = new Element(1, true); var el = new Element(1, false); }).toThrow(); expect(function () { @@ -62,6 +64,7 @@ describe('simple-linked-list', function () { var el = new Element(1, {}); }).toThrow(); }); + /* eslint-enable no-unused-vars */ describe('List', function () { xit('is a constructor', function () { diff --git a/exercises/space-age/README.md b/exercises/space-age/README.md index 68bc8ed3..523cc173 100644 --- a/exercises/space-age/README.md +++ b/exercises/space-age/README.md @@ -12,33 +12,36 @@ Given an age in seconds, calculate how old someone would be on: - Neptune: orbital period 164.79132 Earth years So if you were told someone were 1,000,000,000 seconds old, you should -be able to say that they're 31 Earth-years old. +be able to say that they're 31.69 Earth-years old. If you're wondering why Pluto didn't make the cut, go watch [this youtube video](http://www.youtube.com/watch?v=Z_2gbGXzFbs). ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine space-age.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/strain/README.md b/exercises/strain/README.md index f726bb2f..f58e2b2d 100644 --- a/exercises/strain/README.md +++ b/exercises/strain/README.md @@ -35,26 +35,29 @@ basic tools instead. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine strain.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/sublist/README.md b/exercises/sublist/README.md index 974d3f06..0b5d6d8c 100644 --- a/exercises/sublist/README.md +++ b/exercises/sublist/README.md @@ -19,32 +19,29 @@ Examples: ## Setup -Go through the setup instructions for ECMAScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/ecmascript +http://exercism.io/languages/javascript/installation -## Requirements +## Running the test suite -Install assignment dependencies: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -```bash -$ npm install -g jasmine +```sh +npm install -g jasmine ``` -## Making the test suite pass +Run the test suite from the exercise directory with: -Execute the tests with: - -```bash -$ jasmine sublist.spec.js +```sh +jasmine sublist.spec.js ``` -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 `xit` to `it`. - +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## 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/sum-of-multiples/README.md b/exercises/sum-of-multiples/README.md index 4ce73e90..ace5cad7 100644 --- a/exercises/sum-of-multiples/README.md +++ b/exercises/sum-of-multiples/README.md @@ -1,38 +1,38 @@ -# Sum of Multiples +# Sum Of Multiples -Given a number, find the sum of all the multiples of particular numbers up to +Given a number, find the sum of all the unique multiples of particular numbers up to but not including that number. -If we list all the natural numbers up to but not including 20 that are -multiples of either 3 or 5, we get 3, 5, 6 and 9, 10, 12, 15, and 18. +If we list all the natural numbers below 20 that are multiples of 3 or 5, +we get 3, 5, 6, 9, 10, 12, 15, and 18. The sum of these multiples is 78. -Given a number, find the sum of the multiples of a given set of numbers, -up to but not including that number. - ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine sum-of-multiples.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/sum-of-multiples/sum-of-multiples.spec.js b/exercises/sum-of-multiples/sum-of-multiples.spec.js index 8866cda9..8ff4a443 100644 --- a/exercises/sum-of-multiples/sum-of-multiples.spec.js +++ b/exercises/sum-of-multiples/sum-of-multiples.spec.js @@ -2,38 +2,38 @@ var SumOfMultiples = require('./sum-of-multiples'); describe('SumOfMultiples', function () { it('to 1', function () { - expect(SumOfMultiples([3, 5]).to(1)).toBe(0); + expect(new SumOfMultiples([3, 5]).to(1)).toBe(0); }); xit('to 3', function () { - expect(SumOfMultiples([3, 5]).to(4)).toBe(3); + expect(new SumOfMultiples([3, 5]).to(4)).toBe(3); }); xit('to 10', function () { - expect(SumOfMultiples([3, 5]).to(10)).toBe(23); + expect(new SumOfMultiples([3, 5]).to(10)).toBe(23); }); xit('to 100', function () { - expect(SumOfMultiples([3, 5]).to(100)).toBe(2318); + expect(new SumOfMultiples([3, 5]).to(100)).toBe(2318); }); xit('to 1000', function () { - expect(SumOfMultiples([3, 5]).to(1000)).toBe(233168); + expect(new SumOfMultiples([3, 5]).to(1000)).toBe(233168); }); xit('[7, 13, 17] to 20', function () { - expect(SumOfMultiples([7, 13, 17]).to(20)).toBe(51); + expect(new SumOfMultiples([7, 13, 17]).to(20)).toBe(51); }); xit('[4, 6] to 15', function () { - expect(SumOfMultiples([4, 6]).to(15)).toBe(30); + expect(new SumOfMultiples([4, 6]).to(15)).toBe(30); }); xit('[5, 6, 8] to 150', function () { - expect(SumOfMultiples([5, 6, 8]).to(150)).toBe(4419); + expect(new SumOfMultiples([5, 6, 8]).to(150)).toBe(4419); }); xit('[43, 47] to 10000', function () { - expect(SumOfMultiples([43, 47]).to(10000)).toBe(2203160); + expect(new SumOfMultiples([43, 47]).to(10000)).toBe(2203160); }); }); diff --git a/exercises/transpose/README.md b/exercises/transpose/README.md index 45e73ca0..05c69022 100644 --- a/exercises/transpose/README.md +++ b/exercises/transpose/README.md @@ -60,26 +60,29 @@ the corresponding output row should contain the spaces in its right-most column( ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js - -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine transpose.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/triangle/README.md b/exercises/triangle/README.md index 32272340..10d05dd2 100644 --- a/exercises/triangle/README.md +++ b/exercises/triangle/README.md @@ -2,45 +2,51 @@ Determine if a triangle is equilateral, isosceles, or scalene. -An _equilateral_ triangle has all three sides the same length.
+An _equilateral_ triangle has all three sides the same length. + An _isosceles_ triangle has at least two sides the same length. (It is sometimes specified as having exactly two sides the same length, but for the purposes of -this exercise we'll say at least two.)
+this exercise we'll say at least two.) + A _scalene_ triangle has all sides of different lengths. ## Note -For a shape to be a triangle at all, all sides have to be of length > 0, and -the sum of the lengths of any two sides must be greater than or equal to the +For a shape to be a triangle at all, all sides have to be of length > 0, and +the sum of the lengths of any two sides must be greater than or equal to the length of the third side. See [Triangle Inequality](https://en.wikipedia.org/wiki/Triangle_inequality). ## Dig Deeper -The case where the sum of the lengths of two sides _equals_ that of the -third is known as a _degenerate_ triangle - it has zero area and looks like +The case where the sum of the lengths of two sides _equals_ that of the +third is known as a _degenerate_ triangle - it has zero area and looks like a single line. Feel free to add your own code/tests to check for degenerate triangles. -## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +## Setup -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine triangle.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/triangle/example.js b/exercises/triangle/example.js index d3f5f614..eb2b9a83 100644 --- a/exercises/triangle/example.js +++ b/exercises/triangle/example.js @@ -22,7 +22,6 @@ function Triangle(a, b, c) { }; this.violatesInequality = function () { - var a = this.sides[0], b = this.sides[1], c = this.sides[2]; return (a + b < c) || (a + c < b) || (b + c < a); }; @@ -50,7 +49,9 @@ function Triangle(a, b, c) { var uniqueSides = []; for (var uniqueSide in uniques) { - uniqueSides.push(uniqueSide); + if (uniques.hasOwnProperty(uniqueSide)) { + uniqueSides.push(uniqueSide); + } } return uniqueSides; diff --git a/exercises/trinary/README.md b/exercises/trinary/README.md index 5d4fd424..16f94ea3 100644 --- a/exercises/trinary/README.md +++ b/exercises/trinary/README.md @@ -11,7 +11,7 @@ Trinary numbers contain three symbols: 0, 1, and 2. The last place in a trinary number is the 1's place. The second to last is the 3's place, the third to last is the 9's place, etc. -```bash +```shell # "102012" 1 0 2 0 1 2 # the number 1*3^5 + 0*3^4 + 2*3^3 + 0*3^2 + 1*3^1 + 2*3^0 # the value @@ -23,26 +23,29 @@ conversion, pretend it doesn't exist and implement it yourself. ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js - -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine trinary.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/trinary/example.js b/exercises/trinary/example.js index 15c0c90b..a580034f 100644 --- a/exercises/trinary/example.js +++ b/exercises/trinary/example.js @@ -14,5 +14,5 @@ Trinary.prototype.toDecimal = function () { }; Trinary.prototype.accumulator = function (decimal, digit, index) { - return decimal += digit * Math.pow(BASE, index); + return decimal + digit * Math.pow(BASE, index); }; diff --git a/exercises/twelve-days/README.md b/exercises/twelve-days/README.md index 749a02a4..9647f728 100644 --- a/exercises/twelve-days/README.md +++ b/exercises/twelve-days/README.md @@ -2,7 +2,7 @@ Output the lyrics to 'The Twelve Days of Christmas'. -``` +```text On the first day of Christmas my true love gave to me, a Partridge in a Pear Tree. On the second day of Christmas my true love gave to me, two Turtle Doves, and a Partridge in a Pear Tree. @@ -28,34 +28,35 @@ On the eleventh day of Christmas my true love gave to me, eleven Pipers Piping, On the twelfth day of Christmas my true love gave to me, twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree. ``` - ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the test suite pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: - - jasmine hello-world.spec.js +```sh +npm install -g jasmine +``` -In many test suites all but the first test have been skipped. +Run the test suite from the exercise directory with: -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +```sh +jasmine twelve-days.spec.js +``` +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source Wikipedia [http://en.wikipedia.org/wiki/The_Twelve_Days_of_Christmas_(song)](http://en.wikipedia.org/wiki/The_Twelve_Days_of_Christmas_(song)) ## Submitting Incomplete Solutions -It's possible to submit an incomplete solution so you can see how others have completed the exercise. \ No newline at end of file +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/two-bucket/README.md b/exercises/two-bucket/README.md index 493d70c2..dfa17296 100644 --- a/exercises/two-bucket/README.md +++ b/exercises/two-bucket/README.md @@ -4,22 +4,22 @@ Given two buckets of different size, demonstrate how to measure an exact number Since this mathematical problem is fairly subject to interpretation / individual approach, the tests have been written specifically to expect one overarching solution. -To help, the tests provide you with which bucket to fill first. That means, when starting with the larger bucket full, you are NOT allowed at any point to have the smaller bucket full and the larger bucket empty (aka, the opposite starting point); that would defeat the purpose of comparing both approaches! +To help, the tests provide you with which bucket to fill first. That means, when starting with the larger bucket full, you are NOT allowed at any point to have the smaller bucket full and the larger bucket empty (aka, the opposite starting point); that would defeat the purpose of comparing both approaches! Your program will take as input: -- the size of bucket one, passed as a numeric value -- the size of bucket two, passed as a numeric value -- the desired number of liters to reach, passed as a numeric value -- which bucket to fill first, passed as a String (either 'one' or 'two') +- the size of bucket one +- the size of bucket two +- the desired number of liters to reach +- which bucket to fill first, either bucket one or bucket two Your program should determine: -- the total number of "moves" it should take to reach the desired number of liters, including the first fill - expects a numeric value -- which bucket should end up with the desired number of liters (let's say this is bucket A) - expects a String (either 'one' or 'two') -- how many liters are left in the other bucket (bucket B) - expects a numeric value +- the total number of "moves" it should take to reach the desired number of liters, including the first fill +- which bucket should end up with the desired number of liters (let's say this is bucket A) - either bucket one or bucket two +- how many liters are left in the other bucket (bucket B) -Note: any time a change is made to either or both buckets counts as one (1) move. +Note: any time a change is made to either or both buckets counts as one (1) move. -Example: +Example: Bucket one can hold up to 7 liters, and bucket two can hold up to 11 liters. Let's say bucket one, at a given step, is holding 7 liters, and bucket two is holding 8 liters (7,8). If you empty bucket one and make no change to bucket two, leaving you with 0 liters and 8 liters respectively (0,8), that counts as one "move". Instead, if you had poured from bucket one into bucket two until bucket two was full, leaving you with 4 liters in bucket one and 11 liters in bucket two (4,11), that would count as only one "move" as well. To conclude, the only valid moves are: @@ -31,26 +31,29 @@ Written with <3 at [Fullstack Academy](http://www.fullstackacademy.com/) by [Lin ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: -http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation -## Making the Test Suite Pass +## Running the test suite -Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine two-bucket.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`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/two-bucket/two-bucket.spec.js b/exercises/two-bucket/two-bucket.spec.js index 248b7ab4..0edf78a0 100644 --- a/exercises/two-bucket/two-bucket.spec.js +++ b/exercises/two-bucket/two-bucket.spec.js @@ -1,7 +1,7 @@ var TwoBucket = require('./two-bucket'); describe('TwoBucket', function () { - describe('Measure using bucket one of size 3 and bucket two of size 5 - ', function () { + describe('Measure using bucket one of size 3 and bucket two of size 5', function () { var bucketOne = 3; var bucketTwo = 5; var goal = 1; @@ -23,7 +23,7 @@ describe('TwoBucket', function () { }); }); - describe('Measure using bucket one of size 7 and bucket two of size 11 - ', function () { + describe('Measure using bucket one of size 7 and bucket two of size 11', function () { var bucketOne = 7; var bucketTwo = 11; var goal = 2; diff --git a/exercises/two-fer/README.md b/exercises/two-fer/README.md new file mode 100644 index 00000000..868b6c46 --- /dev/null +++ b/exercises/two-fer/README.md @@ -0,0 +1,46 @@ +# Two Fer + +`Two-fer` or `2-fer` is short for two for one. One for you and one for me. + +```text +"One for X, one for me." +``` + +When X is a name or "you". + +If the given name is "Alice", the result should be "One for Alice, one for me." +If no name is given, the result should be "One for you, one for me." + + +## Setup + +Go through the setup instructions for JavaScript to install the + necessary dependencies: + +http://exercism.io/languages/javascript/installation + +## Running the test suite + +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: + +```sh +npm install -g jasmine +``` + +Run the test suite from the exercise directory with: + +```sh +jasmine two-fer.spec.js +``` + +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. + +## Source + +This is an exercise to introduce users to basic programming constructs, just after Hello World. [https://en.wikipedia.org/wiki/Two-fer](https://en.wikipedia.org/wiki/Two-fer) + +## 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/two-fer/example.js b/exercises/two-fer/example.js new file mode 100644 index 00000000..5719a4cc --- /dev/null +++ b/exercises/two-fer/example.js @@ -0,0 +1,10 @@ +var TwoFer = function () {}; + +TwoFer.prototype.twoFer = function (who) { + if (who) { + return 'One for ' + who + ', one for me.'; + } + return 'One for you, one for me.'; +}; + +module.exports = TwoFer; diff --git a/exercises/two-fer/two-fer.js b/exercises/two-fer/two-fer.js new file mode 100644 index 00000000..88ab610d --- /dev/null +++ b/exercises/two-fer/two-fer.js @@ -0,0 +1,12 @@ +var TwoFer = function () {}; + +TwoFer.prototype.twoFer = function (who) { + // your code goes here + // You will have to use the parameter who + // in some way. In this example, it is just + // returned, but your solution will have to + // use a conditional. + return who; +}; + +module.exports = TwoFer; diff --git a/exercises/two-fer/two-fer.spec.js b/exercises/two-fer/two-fer.spec.js new file mode 100644 index 00000000..fe262efa --- /dev/null +++ b/exercises/two-fer/two-fer.spec.js @@ -0,0 +1,18 @@ + +var TwoFer = require('./two-fer'); + +describe('Two Fer', function () { + var twoFer = new TwoFer(); + + it('gives one to you if no parameter given', function () { + expect(twoFer.twoFer()).toEqual('One for you, one for me.'); + }); + + xit('gives one to Alice if \'Alice\' is given', function () { + expect(twoFer.twoFer('Alice')).toEqual('One for Alice, one for me.'); + }); + + xit('gives one to Bob if \'Bob\' is given', function () { + expect(twoFer.twoFer('Bob')).toEqual('One for Bob, one for me.'); + }); +}); diff --git a/exercises/variable-length-quantity/README.md b/exercises/variable-length-quantity/README.md new file mode 100644 index 00000000..7e1203a4 --- /dev/null +++ b/exercises/variable-length-quantity/README.md @@ -0,0 +1,62 @@ +# Variable Length Quantity + +Implement variable length quantity encoding and decoding. + +The goal of this exercise is to implement [VLQ](https://en.wikipedia.org/wiki/Variable-length_quantity) encoding/decoding. + +In short, the goal of this encoding is to encode integer values in a way that would save bytes. +Only the first 7 bits of each byte is significant (right-justified; sort of like an ASCII byte). +So, if you have a 32-bit value, you have to unpack it into a series of 7-bit bytes. +Of course, you will have a variable number of bytes depending upon your integer. +To indicate which is the last byte of the series, you leave bit #7 clear. +In all of the preceding bytes, you set bit #7. + +So, if an integer is between `0-127`, it can be represented as one byte. +Although VLQ can deal with numbers of arbitrary sizes, for this exercise we will restrict ourselves to only numbers that fit in a 32-bit unsigned integer. +Here are examples of integers as 32-bit values, and the variable length quantities that they translate to: + +```text + NUMBER VARIABLE QUANTITY +00000000 00 +00000040 40 +0000007F 7F +00000080 81 00 +00002000 C0 00 +00003FFF FF 7F +00004000 81 80 00 +00100000 C0 80 00 +001FFFFF FF FF 7F +00200000 81 80 80 00 +08000000 C0 80 80 00 +0FFFFFFF FF FF FF 7F +``` + +## 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 Hello World exercise: + + jasmine hello-world.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 + +A poor Splice developer having to implement MIDI encoding/decoding. [https://splice.com](https://splice.com) + +## 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/variable-length-quantity/example.js b/exercises/variable-length-quantity/example.js new file mode 100644 index 00000000..9aeec820 --- /dev/null +++ b/exercises/variable-length-quantity/example.js @@ -0,0 +1,51 @@ +var LENGTH = 7; +var CONT_BITS = 1 << LENGTH; +var DATA_BITS = CONT_BITS - 1; + +var encodeOne = function (val) { + var buf = []; + var left = val; + + while (left) { + var bits = left & DATA_BITS | CONT_BITS; // set continuation everywhere + left = left >>> LENGTH; + buf.push(bits); + } + buf[0] = buf[0] & DATA_BITS; // cancel the last continuation + return buf.reverse(); +}; + +var decodeOne = function (buf) { + var val = 0; + + for (var i = 0; i < buf.length; i++) { + val = val << LENGTH | buf[i] & DATA_BITS; + } + return val >>> 0; // convert to unsigned 32-bit +}; + +module.exports = { + encode: function encode(data) { + var buf = []; + + for (var i = 0; i < data.length; i++) { + buf = buf.concat(encodeOne(data[i])); + } + return buf; + }, + decode: function decode(data) { + var start = 0; + var vals = []; + + for (var i = 0; i < data.length; i++) { + if (~data[i] & CONT_BITS) { + vals.push(decodeOne(data.slice(start, i + 1))); + start = i + 1; + } + } + if (start < data.length) { + throw new Error('Incomplete sequence'); + } + return vals; + } +}; diff --git a/exercises/variable-length-quantity/variable-length-quantity.spec.js b/exercises/variable-length-quantity/variable-length-quantity.spec.js new file mode 100644 index 00000000..43d066dc --- /dev/null +++ b/exercises/variable-length-quantity/variable-length-quantity.spec.js @@ -0,0 +1,115 @@ +var VLQ = require('./variable-length-quantity'); + +describe('VariableLengthQuantity', function () { + describe('Encode a series of integers, producing a series of bytes.', function () { + it('zero', function () { + expect(VLQ.encode([0])).toEqual([0]); + }); + + it('arbitrary single byte', function () { + expect(VLQ.encode([0x40])).toEqual([0x40]); + }); + + it('largest single byte', function () { + expect(VLQ.encode([0x7f])).toEqual([0x7f]); + }); + + it('smallest double byte', function () { + expect(VLQ.encode([0x80])).toEqual([0x81, 0]); + }); + + it('arbitrary double byte', function () { + expect(VLQ.encode([0x2000])).toEqual([0xc0, 0]); + }); + + it('largest double byte', function () { + expect(VLQ.encode([0x3fff])).toEqual([0xff, 0x7f]); + }); + + it('smallest triple byte', function () { + expect(VLQ.encode([0x4000])).toEqual([0x81, 0x80, 0]); + }); + + it('arbitrary triple byte', function () { + expect(VLQ.encode([0x100000])).toEqual([0xc0, 0x80, 0]); + }); + + it('largest triple byte', function () { + expect(VLQ.encode([0x1fffff])).toEqual([0xff, 0xff, 0x7f]); + }); + + it('smallest quadruple byte', function () { + expect(VLQ.encode([0x200000])).toEqual([0x81, 0x80, 0x80, 0]); + }); + + it('arbitrary quadruple byte', function () { + expect(VLQ.encode([0x8000000])).toEqual([0xc0, 0x80, 0x80, 0]); + }); + + it('largest quadruple byte', function () { + expect(VLQ.encode([0xfffffff])).toEqual([0xff, 0xff, 0xff, 0x7f]); + }); + + it('smallest quintuple byte', function () { + expect(VLQ.encode([0x10000000])).toEqual([0x81, 0x80, 0x80, 0x80, 0]); + }); + + it('arbitrary quintuple byte', function () { + expect(VLQ.encode([0xff000000])).toEqual([0x8f, 0xf8, 0x80, 0x80, 0]); + }); + + it('maximum 32-bit integer input', function () { + expect(VLQ.encode([0xffffffff])).toEqual([0x8f, 0xff, 0xff, 0xff, 0x7f]); + }); + + it('two single-byte values', function () { + expect(VLQ.encode([0x40, 0x7f])).toEqual([0x40, 0x7f]); + }); + + it('two multi-byte values', function () { + expect(VLQ.encode([0x4000, 0x123456])).toEqual([0x81, 0x80, 0, 0xc8, 0xe8, 0x56]); + }); + + it('many multi-byte values', function () { + var input = [0x2000, 0x123456, 0xfffffff, 0, 0x3fff, 0x4000]; + var expected = [0xc0, 0, 0xc8, 0xe8, 0x56, 0xff, 0xff, 0xff, 0x7f, 0, 0xff, 0x7f, 0x81, 0x80, 0]; + expect(VLQ.encode(input)).toEqual(expected); + }); + }); + + describe('Decode a series of bytes, producing a series of integers.', function () { + it('one byte', function () { + expect(VLQ.decode([0x7f])).toEqual([0x7f]); + }); + + it('two bytes', function () { + expect(VLQ.decode([0xc0, 0])).toEqual([0x2000]); + }); + + it('three bytes', function () { + expect(VLQ.decode([0xff, 0xff, 0x7f])).toEqual([0x1fffff]); + }); + + it('four bytes', function () { + expect(VLQ.decode([0x81, 0x80, 0x80, 0])).toEqual([0x200000]); + }); + + it('maximum 32-bit integer', function () { + expect(VLQ.decode([0x8f, 0xff, 0xff, 0xff, 0x7f])).toEqual([0xffffffff]); + }); + + it('incomplete sequence causes error', function () { + expect(function () { VLQ.decode([0xff]); }).toThrow(new Error('Incomplete sequence')); + }); + + it('incomplete sequence causes error, even if value is zero', function () { + expect(function () { VLQ.decode([0x80]); }).toThrow(new Error('Incomplete sequence')); + }); + + it('multiple values', function () { + var input = [0xc0, 0, 0xc8, 0xe8, 0x56, 0xff, 0xff, 0xff, 0x7f, 0, 0xff, 0x7f, 0x81, 0x80, 0]; + var expected = [0x2000, 0x123456, 0xfffffff, 0, 0x3fff, 0x4000]; + expect(VLQ.decode(input)).toEqual(expected); + }); + }); +}); diff --git a/exercises/word-count/README.md b/exercises/word-count/README.md index ae006d10..e0bd287f 100644 --- a/exercises/word-count/README.md +++ b/exercises/word-count/README.md @@ -4,36 +4,38 @@ Given a phrase, count the occurrences of each word in that phrase. For example for the input `"olly olly in come free"` -```plain +```text olly: 2 in: 1 come: 1 free: 1 ``` - ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine word-count.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/wordy/README.md b/exercises/wordy/README.md index 4186cc06..c4950341 100644 --- a/exercises/wordy/README.md +++ b/exercises/wordy/README.md @@ -2,7 +2,6 @@ Parse and evaluate simple math word problems returning the answer as an integer. - ## Iteration 1 — Addition Add two numbers together. @@ -13,7 +12,6 @@ Evaluates to 18. Handle large numbers and negative numbers. - ## Iteration 2 — Subtraction, Multiplication and Division Now, perform the other three operations. @@ -30,7 +28,6 @@ Now, perform the other three operations. 5 - ## Iteration 3 — Multiple Operations Handle a set of operations, in sequence. @@ -46,7 +43,6 @@ left-to-right, _ignoring the typical order of operations._ 15 (i.e. not 9) - ## Bonus — Exponentials If you'd like, handle exponentials. @@ -55,29 +51,31 @@ If you'd like, handle exponentials. 32 - ## Setup -Go through the setup instructions for JavaScript to -install the necessary dependencies: - -http://exercism.io/languages/javascript +Go through the setup instructions for JavaScript to install the + necessary dependencies: -## Making the Test Suite Pass +http://exercism.io/languages/javascript/installation -Execute the tests with: +## Running the test suite - jasmine .spec.js +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: -Replace `` with the name of the current exercise. E.g., to -test the Hello World exercise: +```sh +npm install -g jasmine +``` - jasmine hello-world.spec.js +Run the test suite from the exercise directory with: -In many test suites all but the first test have been skipped. +```sh +jasmine wordy.spec.js +``` -Once you get a test passing, you can unskip the next one by -changing `xit` to `it`. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. ## Source diff --git a/exercises/wordy/example.js b/exercises/wordy/example.js index ce01bbd7..819cae70 100644 --- a/exercises/wordy/example.js +++ b/exercises/wordy/example.js @@ -47,11 +47,11 @@ WordProblem.prototype.evaluate = function () { var out = 0; var m = this.matches; - if (m[1] !== undefined && m[2] !== undefined && m[3] !== undefined) { + if ( (typeof m[1]) === 'string' && (typeof m[2]) === 'string' && (typeof m[3]) === 'string') { out = this.operate(m[2], m[1], m[3]); } - if (m[4] !== undefined && m[5] !== undefined) { + if ( (typeof m[4]) === 'string' && (typeof m[5]) === 'string') { out = this.operate(m[4], out, m[5]); } diff --git a/exercises/zipper/README.md b/exercises/zipper/README.md index ae7adf1a..ab780272 100644 --- a/exercises/zipper/README.md +++ b/exercises/zipper/README.md @@ -3,7 +3,7 @@ Creating a zipper for a binary tree. [Zippers](https://en.wikipedia.org/wiki/Zipper_%28data_structure%29) are -a way purely functional of navigating within a data structure and +a purely functional way of navigating within a data structure and manipulating it. They essentially contain a data structure and a pointer into that data structure (called the focus). @@ -27,29 +27,31 @@ list of child nodes) a zipper might support these operations: `next` node if possible otherwise to the `prev` node if possible, otherwise to the parent node, returns a new zipper) - ## Setup +## Setup - Go through the setup instructions for JavaScript to - install the necessary dependencies: +Go through the setup instructions for JavaScript to install the + necessary dependencies: - http://exercism.io/languages/javascript +http://exercism.io/languages/javascript/installation - ## Making the Test Suite Pass +## Running the test suite - Execute the tests with: +The provided test suite uses [Jasmine](https://jasmine.github.io/). +You can install it by opening a terminal window and running the +following command: - jasmine .spec.js +```sh +npm install -g jasmine +``` - Replace `` with the name of the current exercise. E.g., to - test the Hello World exercise: +Run the test suite from the exercise directory with: - jasmine hello-world.spec.js +```sh +jasmine zipper.spec.js +``` - All but the first test have been skipped. +In many test suites all but the first test have been marked "pending". +Once you get a test passing, activate the next one by changing `xit` to `it`. - Once you get a test passing, you can unskip the next one by - changing `xit` to `it`. - - - ## Submitting Incomplete Solutions - It's possible to submit an incomplete solution so you can see how others have completed the exercise. +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/package-lock.json b/package-lock.json index 5429eb3b..94eab4b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,10 +4,81 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@babel/code-frame": { + "version": "7.0.0-beta.31", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0-beta.31.tgz", + "integrity": "sha512-yd7CkUughvHQoEahQqcMdrZw6o/6PwUxiRkfZuVDVHCDe77mysD/suoNyk5mK6phTnRW1kyIbPHyCJgxw++LXg==", + "dev": true, + "requires": { + "chalk": "2.3.0", + "esutils": "2.0.2", + "js-tokens": "3.0.2" + } + }, + "@babel/helper-function-name": { + "version": "7.0.0-beta.31", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.0.0-beta.31.tgz", + "integrity": "sha512-c+DAyp8LMm2nzSs2uXEuxp4LYGSUYEyHtU3fU57avFChjsnTmmpWmXj2dv0yUxHTEydgVAv5fIzA+4KJwoqWDA==", + "dev": true, + "requires": { + "@babel/helper-get-function-arity": "7.0.0-beta.31", + "@babel/template": "7.0.0-beta.31", + "@babel/traverse": "7.0.0-beta.31", + "@babel/types": "7.0.0-beta.31" + } + }, + "@babel/helper-get-function-arity": { + "version": "7.0.0-beta.31", + "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.31.tgz", + "integrity": "sha512-m7rVVX/dMLbbB9NCzKYRrrFb0qZxgpmQ4Wv6y7zEsB6skoJHRuXVeb/hAFze79vXBbuD63ci7AVHXzAdZSk9KQ==", + "dev": true, + "requires": { + "@babel/types": "7.0.0-beta.31" + } + }, + "@babel/template": { + "version": "7.0.0-beta.31", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.0.0-beta.31.tgz", + "integrity": "sha512-97IRmLvoDhIDSQkqklVt3UCxJsv0LUEVb/0DzXWtc8Lgiyxj567qZkmTG9aR21CmcJVVIvq2Y/moZj4oEpl5AA==", + "dev": true, + "requires": { + "@babel/code-frame": "7.0.0-beta.31", + "@babel/types": "7.0.0-beta.31", + "babylon": "7.0.0-beta.31", + "lodash": "4.17.4" + } + }, + "@babel/traverse": { + "version": "7.0.0-beta.31", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.0.0-beta.31.tgz", + "integrity": "sha512-3N+VJW+KlezEjFBG7WSYeMyC5kIqVLPb/PGSzCDPFcJrnArluD1GIl7Y3xC7cjKiTq2/JohaLWHVPjJWHlo9Gg==", + "dev": true, + "requires": { + "@babel/code-frame": "7.0.0-beta.31", + "@babel/helper-function-name": "7.0.0-beta.31", + "@babel/types": "7.0.0-beta.31", + "babylon": "7.0.0-beta.31", + "debug": "3.1.0", + "globals": "10.4.0", + "invariant": "2.2.2", + "lodash": "4.17.4" + } + }, + "@babel/types": { + "version": "7.0.0-beta.31", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.0.0-beta.31.tgz", + "integrity": "sha512-exAHB+NeFGxkfQ5dSUD03xl3zYGneeSk2Mw2ldTt/nTvYxuDiuSp3DlxgUBgzbdTFG4fbwPk0WtKWOoTXCmNGg==", + "dev": true, + "requires": { + "esutils": "2.0.2", + "lodash": "4.17.4", + "to-fast-properties": "2.0.0" + } + }, "acorn": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.1.2.tgz", - "integrity": "sha512-o96FZLJBPY1lvTuJylGA9Bk3t/GKPPJG8H0ydQQl01crzwJgspa4AEIq/pVTXigmK0PHVQhiAtn8WMBLL9D2WA==", + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.2.1.tgz", + "integrity": "sha512-jG0u7c4Ly+3QkkW18V+NRDN+4bWHdln30NL1ZL2AvFZZmQe/BfopYCtghCKKVBUSetZ4QKcyA0pY6/4Gw8Pv8w==", "dev": true }, "acorn-jsx": { @@ -28,21 +99,21 @@ } }, "ajv": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.2.3.tgz", - "integrity": "sha1-wG9Zh3jETGsWGrr+NGa4GtGBTtI=", + "version": "5.5.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.1.tgz", + "integrity": "sha1-s4u4h22ehr7plJVqBOch6IskjrI=", "dev": true, "requires": { "co": "4.6.0", "fast-deep-equal": "1.0.0", - "json-schema-traverse": "0.3.1", - "json-stable-stringify": "1.0.1" + "fast-json-stable-stringify": "2.0.0", + "json-schema-traverse": "0.3.1" } }, "ajv-keywords": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-2.1.0.tgz", - "integrity": "sha1-opbhf3v658HOT34N5T0pyzIWLfA=", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-2.1.1.tgz", + "integrity": "sha1-YXmX/F9gV2iUxDX5QNgZ4TW4B2I=", "dev": true }, "ansi-escapes": { @@ -63,7 +134,7 @@ "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", "dev": true, "requires": { - "color-convert": "1.9.0" + "color-convert": "1.9.1" } }, "argparse": { @@ -82,7 +153,7 @@ "dev": true, "requires": { "define-properties": "1.1.2", - "es-abstract": "1.8.2" + "es-abstract": "1.10.0" } }, "array-union": { @@ -113,110 +184,68 @@ "dev": true }, "babel-code-frame": { - "version": "7.0.0-beta.0", - "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-7.0.0-beta.0.tgz", - "integrity": "sha512-/xr1ADm5bnTjjN+xwoXb7lF4v2rnxMzNZzFU7h8SxB+qB6+IqSTOOqVcpaPTUC2Non/MbQxS3OIZnJpQ2X21aQ==", + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", + "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", "dev": true, "requires": { - "chalk": "2.1.0", + "chalk": "1.1.3", "esutils": "2.0.2", "js-tokens": "3.0.2" - } - }, - "babel-eslint": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-8.0.1.tgz", - "integrity": "sha512-h3moF6PCTQE06UjMMG+ydZSBvZ4Q7rqPE/5WAUOvUyHYUTqxm8JVhjZRiG1avI/tGVOK4BnZLDQapyLzh8DeKg==", - "dev": true, - "requires": { - "babel-code-frame": "7.0.0-beta.0", - "babel-traverse": "7.0.0-beta.0", - "babel-types": "7.0.0-beta.0", - "babylon": "7.0.0-beta.22" - } - }, - "babel-helper-function-name": { - "version": "7.0.0-beta.0", - "resolved": "https://registry.npmjs.org/babel-helper-function-name/-/babel-helper-function-name-7.0.0-beta.0.tgz", - "integrity": "sha512-DaQccFBBWBEzMdqbKmNXamY0m1yLHJGOdbbEsNoGdJrrU7wAF3wwowtDDPzF0ZT3SqJXPgZW/P2kgBX9moMuAA==", - "dev": true, - "requires": { - "babel-helper-get-function-arity": "7.0.0-beta.0", - "babel-template": "7.0.0-beta.0", - "babel-traverse": "7.0.0-beta.0", - "babel-types": "7.0.0-beta.0" - } - }, - "babel-helper-get-function-arity": { - "version": "7.0.0-beta.0", - "resolved": "https://registry.npmjs.org/babel-helper-get-function-arity/-/babel-helper-get-function-arity-7.0.0-beta.0.tgz", - "integrity": "sha512-csqAic15/2Vm1951nJxkkL9K8E6ojyNF/eAOjk7pqJlO8kvgrccGNFCV9eDwcGHDPe5AjvJGwVSAcQ5fit9wuA==", - "dev": true, - "requires": { - "babel-types": "7.0.0-beta.0" - } - }, - "babel-messages": { - "version": "7.0.0-beta.0", - "resolved": "https://registry.npmjs.org/babel-messages/-/babel-messages-7.0.0-beta.0.tgz", - "integrity": "sha512-eXdShsm9ZTh9AQhlIaAn6HR3xWpxCnK9ZwIDA9QyjnwTgMctGxHHflw4b4RJ3/ZjTL0Vrmvm0tQXPkp49mTAUw==", - "dev": true - }, - "babel-template": { - "version": "7.0.0-beta.0", - "resolved": "https://registry.npmjs.org/babel-template/-/babel-template-7.0.0-beta.0.tgz", - "integrity": "sha512-tmdH+MmmU0F6Ur8humpevSmFzYKbrN3Oru0g5Qyg4R6+sxjnzZmnvzUbsP0aKMr7tB0Ua6xhEb9arKTOsEMkyA==", - "dev": true, - "requires": { - "babel-traverse": "7.0.0-beta.0", - "babel-types": "7.0.0-beta.0", - "babylon": "7.0.0-beta.22", - "lodash": "4.17.4" - } - }, - "babel-traverse": { - "version": "7.0.0-beta.0", - "resolved": "https://registry.npmjs.org/babel-traverse/-/babel-traverse-7.0.0-beta.0.tgz", - "integrity": "sha512-IKzuTqUcQtMRZ0Vv5RjIrGGj33eBKmNTNeRexWSyjPPuAciyNkva1rt7WXPfHfkb+dX7coRAIUhzeTUEzhnwdA==", - "dev": true, - "requires": { - "babel-code-frame": "7.0.0-beta.0", - "babel-helper-function-name": "7.0.0-beta.0", - "babel-messages": "7.0.0-beta.0", - "babel-types": "7.0.0-beta.0", - "babylon": "7.0.0-beta.22", - "debug": "3.1.0", - "globals": "10.1.0", - "invariant": "2.2.2", - "lodash": "4.17.4" }, "dependencies": { - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "dev": true, "requires": { - "ms": "2.0.0" + "ansi-styles": "2.2.1", + "escape-string-regexp": "1.0.5", + "has-ansi": "2.0.0", + "strip-ansi": "3.0.1", + "supports-color": "2.0.0" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "2.1.1" } + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true } } }, - "babel-types": { - "version": "7.0.0-beta.0", - "resolved": "https://registry.npmjs.org/babel-types/-/babel-types-7.0.0-beta.0.tgz", - "integrity": "sha512-rJc2kV9iPJGLlqIY71AM3nPcdkoeLRCDuR07GFgfd3lFl4TsBQq76TxYQQIZ2MONg1HpsqmuoCXr9aZ1Oa4wYw==", + "babel-eslint": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-8.0.3.tgz", + "integrity": "sha512-7D4iUpylEiKJPGbeSAlNddGcmA41PadgZ6UAb6JVyh003h3d0EbZusYFBR/+nBgqtaVJM2J2zUVa3N0hrpMH6g==", "dev": true, "requires": { - "esutils": "2.0.2", - "lodash": "4.17.4", - "to-fast-properties": "2.0.0" + "@babel/code-frame": "7.0.0-beta.31", + "@babel/traverse": "7.0.0-beta.31", + "@babel/types": "7.0.0-beta.31", + "babylon": "7.0.0-beta.31" } }, "babylon": { - "version": "7.0.0-beta.22", - "resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.22.tgz", - "integrity": "sha512-Yl7iT8QGrS8OfR7p6R12AJexQm+brKwrryai4VWZ7NHUbPoZ5al3+klhvl/14shXZiLa7uK//OIFuZ1/RKHgoA==", + "version": "7.0.0-beta.31", + "resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.31.tgz", + "integrity": "sha512-6lm2mV3S51yEnKmQQNnswoABL1U1H1KHoCCVwdwI3hvIv+W7ya4ki7Aw4o4KxtUHjNKkK5WpZb22rrMMOcJXJQ==", "dev": true }, "balanced-match": { @@ -257,16 +286,22 @@ "dev": true }, "chalk": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.1.0.tgz", - "integrity": "sha512-LUHGS/dge4ujbXMJrnihYMcL4AoOweGnw9Tp3kQuqy1Kx5c1qKjqvMJZ6nVJPMWJtKCTN72ZogH3oeSO9g9rXQ==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.0.tgz", + "integrity": "sha512-Az5zJR2CBujap2rqXGaJKaPHyJ0IrUimvYNX+ncCy8PJP4ltOGTrHUIo097ZaL2zMeKYpiCdqDvS6zdrTFok3Q==", "dev": true, "requires": { "ansi-styles": "3.2.0", "escape-string-regexp": "1.0.5", - "supports-color": "4.4.0" + "supports-color": "4.5.0" } }, + "chardet": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz", + "integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=", + "dev": true + }, "circular-json": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz", @@ -295,9 +330,9 @@ "dev": true }, "color-convert": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.0.tgz", - "integrity": "sha1-Gsz5fdc5uYO/mU1W/sj5WFNkG3o=", + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.1.tgz", + "integrity": "sha512-mjGanIiwQJskCC18rPR6OmrZ6fm2Lc7PeGFYwCmy5J34wC6F1PzdGL6xeMfmgicfYcNLGuVFA3WzXtIDCQSZxQ==", "dev": true, "requires": { "color-name": "1.1.3" @@ -356,9 +391,9 @@ } }, "debug": { - "version": "2.6.8", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", - "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", "dev": true, "requires": { "ms": "2.0.0" @@ -396,13 +431,12 @@ } }, "doctrine": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", - "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.0.2.tgz", + "integrity": "sha512-y0tm5Pq6ywp3qSTZ1vPgVdAnbDEoeoc5wlOHXoY1c4Wug/a7JvqHIl7BTvwodaHmejWkK/9dSb3sCYfyo/om8A==", "dev": true, "requires": { - "esutils": "2.0.2", - "isarray": "1.0.0" + "esutils": "2.0.2" } }, "encoding": { @@ -424,9 +458,9 @@ } }, "es-abstract": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.8.2.tgz", - "integrity": "sha512-dvhwFL3yjQxNNsOWx6exMlaDrRHCRGMQlnx5lsXDCZ/J7G/frgIIl94zhZSp/galVAYp7VzPi1OrAHta89/yGQ==", + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.10.0.tgz", + "integrity": "sha512-/uh/DhdqIOSkAWifU+8nG78vlQxdLckUdI/sPgy0VhuXi2qJ7T8czBmqIYtLQVpCIFYafChnsRsB5pyb1JdmCQ==", "dev": true, "requires": { "es-to-primitive": "1.1.1", @@ -454,33 +488,33 @@ "dev": true }, "eslint": { - "version": "4.7.2", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.7.2.tgz", - "integrity": "sha1-/29fUZOEiifum2J74+c/ucteZi4=", + "version": "4.13.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.13.1.tgz", + "integrity": "sha512-UCJVV50RtLHYzBp1DZ8CMPtRSg4iVZvjgO9IJHIKyWU/AnJVjtdRikoUPLB29n5pzMB7TnsLQWf0V6VUJfoPfw==", "dev": true, "requires": { - "ajv": "5.2.3", + "ajv": "5.5.1", "babel-code-frame": "6.26.0", - "chalk": "2.1.0", + "chalk": "2.3.0", "concat-stream": "1.6.0", "cross-spawn": "5.1.0", "debug": "3.1.0", - "doctrine": "2.0.0", + "doctrine": "2.0.2", "eslint-scope": "3.7.1", - "espree": "3.5.1", + "espree": "3.5.2", "esquery": "1.0.0", "estraverse": "4.2.0", "esutils": "2.0.2", "file-entry-cache": "2.0.0", "functional-red-black-tree": "1.0.1", "glob": "7.1.2", - "globals": "9.18.0", - "ignore": "3.3.5", + "globals": "11.1.0", + "ignore": "3.3.7", "imurmurhash": "0.1.4", "inquirer": "3.3.0", - "is-resolvable": "1.0.0", + "is-resolvable": "1.0.1", "js-yaml": "3.10.0", - "json-stable-stringify": "1.0.1", + "json-stable-stringify-without-jsonify": "1.0.1", "levn": "0.3.0", "lodash": "4.17.4", "minimatch": "3.0.4", @@ -498,84 +532,18 @@ "text-table": "0.2.0" }, "dependencies": { - "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", - "dev": true - }, - "babel-code-frame": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", - "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", - "dev": true, - "requires": { - "chalk": "1.1.3", - "esutils": "2.0.2", - "js-tokens": "3.0.2" - }, - "dependencies": { - "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", - "dev": true, - "requires": { - "ansi-styles": "2.2.1", - "escape-string-regexp": "1.0.5", - "has-ansi": "2.0.0", - "strip-ansi": "3.0.1", - "supports-color": "2.0.0" - } - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, - "requires": { - "ansi-regex": "2.1.1" - } - } - } - }, - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "doctrine": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.0.0.tgz", - "integrity": "sha1-xz2NKQnSIpHhoAejlYBNqLZl/mM=", - "dev": true, - "requires": { - "esutils": "2.0.2", - "isarray": "1.0.0" - } - }, "globals": { - "version": "9.18.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz", - "integrity": "sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==", - "dev": true - }, - "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.1.0.tgz", + "integrity": "sha512-uEuWt9mqTlPDwSqi+sHjD4nWU/1N+q0fiWI9T1mZpD2UENqX20CFD5T/ziLZvztPaBKl7ZylUi1q6Qfm7E2CiQ==", "dev": true } } }, "eslint-config-airbnb-base": { - "version": "12.0.0", - "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-12.0.0.tgz", - "integrity": "sha512-/XlFQGn3Mkwm642/GYBtOH3pgFX4Z7saBsqqyp96v0bEUPq24nIrZ6N72qAoD0lR2wAne4EC4YsHYkbPfaRfiA==", + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-12.1.0.tgz", + "integrity": "sha512-/vjm0Px5ZCpmJqnjIzcFb9TKZrKWz0gnuG/7Gfkt0Db1ELJR51xkZth+t14rYdqWgX836XbuxtArbIHlVhbLBA==", "dev": true, "requires": { "eslint-restricted-globals": "0.1.1" @@ -604,8 +572,19 @@ "integrity": "sha512-yUtXS15gIcij68NmXmP9Ni77AQuCN0itXbCc/jWd8C6/yKZaSNXicpC8cgvjnxVdmfsosIXrjpzFq7GcDryb6A==", "dev": true, "requires": { - "debug": "2.6.8", - "resolve": "1.4.0" + "debug": "2.6.9", + "resolve": "1.5.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + } } }, "eslint-module-utils": { @@ -614,19 +593,30 @@ "integrity": "sha512-jDI/X5l/6D1rRD/3T43q8Qgbls2nq5km5KSqiwlyUbGo5+04fXhMKdCPhjwbqAa6HXWaMxj8Q4hQDIh7IadJQw==", "dev": true, "requires": { - "debug": "2.6.8", + "debug": "2.6.9", "pkg-dir": "1.0.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + } } }, "eslint-plugin-import": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.7.0.tgz", - "integrity": "sha512-HGYmpU9f/zJaQiKNQOVfHUh2oLWW3STBrCgH0sHTX1xtsxYlH1zjLh8FlQGEIdZSdTbUMaV36WaZ6ImXkenGxQ==", + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.8.0.tgz", + "integrity": "sha512-Rf7dfKJxZ16QuTgVv1OYNxkZcsu/hULFnC+e+w0Gzi6jMC3guQoWQgxYxc54IDRinlb6/0v5z/PxxIKmVctN+g==", "dev": true, "requires": { "builtin-modules": "1.1.1", "contains-path": "0.1.0", - "debug": "2.6.8", + "debug": "2.6.9", "doctrine": "1.5.0", "eslint-import-resolver-node": "0.3.1", "eslint-module-utils": "2.1.1", @@ -634,36 +624,45 @@ "lodash.cond": "4.5.2", "minimatch": "3.0.4", "read-pkg-up": "2.0.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "doctrine": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", + "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", + "dev": true, + "requires": { + "esutils": "2.0.2", + "isarray": "1.0.0" + } + } } }, "eslint-plugin-jasmine": { - "version": "2.8.4", - "resolved": "https://registry.npmjs.org/eslint-plugin-jasmine/-/eslint-plugin-jasmine-2.8.4.tgz", - "integrity": "sha1-Z6VVHj0dXguMa1Sq66uVNw9dN94=", + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-jasmine/-/eslint-plugin-jasmine-2.9.1.tgz", + "integrity": "sha1-IuGaWfFvOl9kOgSroEQ40OMEcDA=", "dev": true }, "eslint-plugin-react": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.4.0.tgz", - "integrity": "sha512-tvjU9u3VqmW2vVuYnE8Qptq+6ji4JltjOjJ9u7VAOxVYkUkyBZWRvNYKbDv5fN+L6wiA+4we9+qQahZ0m63XEA==", + "version": "7.5.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.5.1.tgz", + "integrity": "sha512-YGSjB9Qu6QbVTroUZi66pYky3DfoIPLdHQ/wmrBGyBRnwxQsBXAov9j2rpXt/55i8nyMv6IRWJv2s4d4YnduzQ==", "dev": true, "requires": { - "doctrine": "2.0.0", + "doctrine": "2.0.2", "has": "1.0.1", "jsx-ast-utils": "2.0.1", "prop-types": "15.6.0" - }, - "dependencies": { - "doctrine": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.0.0.tgz", - "integrity": "sha1-xz2NKQnSIpHhoAejlYBNqLZl/mM=", - "dev": true, - "requires": { - "esutils": "2.0.2", - "isarray": "1.0.0" - } - } } }, "eslint-restricted-globals": { @@ -683,12 +682,12 @@ } }, "espree": { - "version": "3.5.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.1.tgz", - "integrity": "sha1-DJiLirRttTEAoZVK5LqZXd0n2H4=", + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.2.tgz", + "integrity": "sha512-sadKeYwaR/aJ3stC2CdvgXu1T16TdYN+qwCpcWbMnGJ8s0zNWemzrvb2GbD4OhmJ/fwpJjudThAlLobGbWZbCQ==", "dev": true, "requires": { - "acorn": "5.1.2", + "acorn": "5.2.1", "acorn-jsx": "3.0.1" } }, @@ -730,13 +729,13 @@ "dev": true }, "external-editor": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.0.5.tgz", - "integrity": "sha512-Msjo64WT5W+NhOpQXh0nOHm+n0RfU1QUwDnKYvJ8dEJ8zlwLrqXNTv5mSUTJpepf41PDJGyhueTw2vNZW+Fr/w==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.1.0.tgz", + "integrity": "sha512-E44iT5QVOUJBKij4IIV3uvxuNlbKS38Tw1HiupxEIHPv9qtC2PrDYohbXV5U+1jnfIXttny8gUhj+oZvflFlzA==", "dev": true, "requires": { + "chardet": "0.4.2", "iconv-lite": "0.4.19", - "jschardet": "1.5.1", "tmp": "0.0.33" } }, @@ -746,6 +745,12 @@ "integrity": "sha1-liVqO8l1WV6zbYLpkp0GDYk0Of8=", "dev": true }, + "fast-json-stable-stringify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", + "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", + "dev": true + }, "fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", @@ -764,7 +769,7 @@ "object-assign": "4.1.1", "promise": "7.3.1", "setimmediate": "1.0.5", - "ua-parser-js": "0.7.14" + "ua-parser-js": "0.7.17" } }, "figures": { @@ -847,9 +852,9 @@ } }, "globals": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-10.1.0.tgz", - "integrity": "sha1-RCWhiBvg0za0qCOoKnvnJdXdmHw=", + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-10.4.0.tgz", + "integrity": "sha512-uNUtxIZpGyuaq+5BqGGQHsL4wUlJAXRqOm6g3Y48/CWNGTLONgBibI0lh6lGxjR2HljFYUfszb+mk4WkgMntsA==", "dev": true }, "globby": { @@ -909,9 +914,9 @@ "dev": true }, "ignore": { - "version": "3.3.5", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.5.tgz", - "integrity": "sha512-JLH93mL8amZQhh/p6mfQgVBH3M6epNq3DfsXsTSuSrInVjwyYlFE1nv2AgfRCC8PoOhM0jwQ5v8s9LgbK7yGDw==", + "version": "3.3.7", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.7.tgz", + "integrity": "sha512-YGG3ejvBNHRqu0559EOxxNFihD0AjpvHlC/pdGKd3X3ofe+CoJkYazwNJYTNebqpPKN+VVQbh4ZFn1DivMNuHA==", "dev": true }, "imurmurhash": { @@ -943,10 +948,10 @@ "dev": true, "requires": { "ansi-escapes": "3.0.0", - "chalk": "2.1.0", + "chalk": "2.3.0", "cli-cursor": "2.1.0", "cli-width": "2.2.0", - "external-editor": "2.0.5", + "external-editor": "2.1.0", "figures": "2.0.0", "lodash": "4.17.4", "mute-stream": "0.0.7", @@ -1012,13 +1017,13 @@ "integrity": "sha1-ZHdYK4IU1gI0YJRWcAO+ip6sBNw=", "dev": true, "requires": { - "is-path-inside": "1.0.0" + "is-path-inside": "1.0.1" } }, "is-path-inside": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-1.0.0.tgz", - "integrity": "sha1-/AbloWg/vaE95mev9xe7wQpI838=", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-1.0.1.tgz", + "integrity": "sha1-jvW33lBDej/cprToZe96pVy0gDY=", "dev": true, "requires": { "path-is-inside": "1.0.2" @@ -1040,13 +1045,10 @@ } }, "is-resolvable": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.0.0.tgz", - "integrity": "sha1-jfV8YeouPFAUCNEA+wE8+NbgzGI=", - "dev": true, - "requires": { - "tryit": "1.0.3" - } + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.0.1.tgz", + "integrity": "sha512-y5CXYbzvB3jTnWAZH1Nl7ykUWb6T3BcTs56HUruwBf8MhF56n1HWqhDWnVFo8GHrUPDgvUUNVhrc2U8W7iqz5g==", + "dev": true }, "is-stream": { "version": "1.1.0", @@ -1082,6 +1084,22 @@ "whatwg-fetch": "2.0.3" } }, + "jasmine": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.1.0.tgz", + "integrity": "sha1-K9Wf1+xuwOistk4J9Fpo7SrRlSo=", + "dev": true, + "requires": { + "glob": "7.1.2", + "jasmine-core": "3.1.0" + } + }, + "jasmine-core": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.1.0.tgz", + "integrity": "sha1-pHheE11d9lAk38kiSVPfWFvSdmw=", + "dev": true + }, "js-tokens": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", @@ -1098,31 +1116,16 @@ "esprima": "4.0.0" } }, - "jschardet": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/jschardet/-/jschardet-1.5.1.tgz", - "integrity": "sha512-vE2hT1D0HLZCLLclfBSfkfTTedhVj0fubHpJBHKwwUWX0nSbhPAfk+SG9rTX95BYNmau8rGFfCeaT6T5OW1C2A==", - "dev": true - }, "json-schema-traverse": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=", "dev": true }, - "json-stable-stringify": { + "json-stable-stringify-without-jsonify": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz", - "integrity": "sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8=", - "dev": true, - "requires": { - "jsonify": "0.0.0" - } - }, - "jsonify": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", - "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", "dev": true }, "jsx-ast-utils": { @@ -1523,9 +1526,9 @@ } }, "resolve": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.4.0.tgz", - "integrity": "sha512-aW7sVKPufyHqOmyyLzg/J+8606v5nevBgaliIlV7nUpVMsDnoBGV/cbSLNjZAg9q0Cfd/+easKVKQ8vOu8fn1Q==", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.5.0.tgz", + "integrity": "sha512-hgoSGrc3pjzAPHNBg+KnFcK2HwlHTs/YrAGUr6qgTVUZmXv1UEXXl0bZNBKMA9fud6lRYFdPGz0xXxycPzmmiw==", "dev": true, "requires": { "path-parse": "1.0.5" @@ -1655,15 +1658,6 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "dev": true, - "requires": { - "safe-buffer": "5.1.1" - } - }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", @@ -1674,6 +1668,15 @@ "strip-ansi": "4.0.0" } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "dev": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, "strip-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", @@ -1704,9 +1707,9 @@ "dev": true }, "supports-color": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", - "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==", + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", + "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", "dev": true, "requires": { "has-flag": "2.0.0" @@ -1718,9 +1721,9 @@ "integrity": "sha512-UUkEAPdSGxtRpiV9ozJ5cMTtYiqz7Ni1OGqLXRCynrvzdtR1p+cfOWe2RJLwvUG8hNanaSRjecIqwOjqeatDsA==", "dev": true, "requires": { - "ajv": "5.2.3", - "ajv-keywords": "2.1.0", - "chalk": "2.1.0", + "ajv": "5.5.1", + "ajv-keywords": "2.1.1", + "chalk": "2.3.0", "lodash": "4.17.4", "slice-ansi": "1.0.0", "string-width": "2.1.1" @@ -1753,12 +1756,6 @@ "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", "dev": true }, - "tryit": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/tryit/-/tryit-1.0.3.tgz", - "integrity": "sha1-OTvnMKlEb9Hq1tpZoBQwjzbCics=", - "dev": true - }, "type-check": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", @@ -1775,9 +1772,9 @@ "dev": true }, "ua-parser-js": { - "version": "0.7.14", - "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.14.tgz", - "integrity": "sha1-EQ1T+kw/MmwSEpK76skE0uAzh8o=", + "version": "0.7.17", + "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.17.tgz", + "integrity": "sha512-uRdSdu1oA1rncCQL7sCj8vSyZkgtL7faaw9Tc9rZ3mGgraQ7+Pdx7w5mnOSF3gw9ZNG6oc+KXfkon3bKuROm0g==", "dev": true }, "util-deprecate": { diff --git a/package.json b/package.json index 223aa598..001c8229 100644 --- a/package.json +++ b/package.json @@ -8,15 +8,28 @@ "license": "MIT", "devDependencies": { "babel-eslint": "^8.0.0", - "eslint": "^4.6.1", - "eslint-config-airbnb-base": "^12.0.0", + "eslint": "^4.10.0", + "eslint-config-airbnb-base": "^12.1.0", "eslint-config-airbnb-es5": "^1.2.0", - "eslint-plugin-import": "^2.7.0", - "eslint-plugin-jasmine": "^2.8.4", - "eslint-plugin-react": "^7.3.0" + "eslint-plugin-import": "^2.8.0", + "eslint-plugin-jasmine": "^2.9.1", + "eslint-plugin-react": "^7.3.0", + "jasmine": "^3.1.0" }, "scripts": { "lint": "eslint .", "lint-fix": "eslint . --fix" + }, + "eslintConfig": { + "plugins": [ + "jasmine" + ], + "env": { + "jasmine": true + }, + "extends": "eslint-config-airbnb-es5", + "rules": { + "func-names": "off" + } } }