From 374ac3a2620ef2aeb20a1e1ea0b6c5b5554024ce Mon Sep 17 00:00:00 2001 From: Derk-Jan Karrenbeld Date: Tue, 26 Mar 2019 19:17:33 +0100 Subject: [PATCH] Add exercise: resistor-color (#648) And replace it in place of leap as core --- config.json | 27 +++++++--- exercises/resistor-color/.eslintrc | 26 ++++++++++ exercises/resistor-color/README.md | 52 +++++++++++++++++++ exercises/resistor-color/babel.config.js | 14 +++++ exercises/resistor-color/example.js | 6 +++ exercises/resistor-color/package.json | 34 ++++++++++++ .../resistor-color/resistor-color.spec.js | 21 ++++++++ 7 files changed, 172 insertions(+), 8 deletions(-) create mode 100644 exercises/resistor-color/.eslintrc create mode 100644 exercises/resistor-color/README.md create mode 100644 exercises/resistor-color/babel.config.js create mode 100644 exercises/resistor-color/example.js create mode 100644 exercises/resistor-color/package.json create mode 100644 exercises/resistor-color/resistor-color.spec.js diff --git a/config.json b/config.json index 8da5f324f9..31d334aa08 100644 --- a/config.json +++ b/config.json @@ -19,15 +19,14 @@ ] }, { - "slug": "leap", - "uuid": "7c8294ee-5924-4bf8-a72f-31d0e2d7d9a0", + "slug": "resistor-color", + "uuid": "53be6837-c224-45f1-bff3-d7f74d6285ce", "core": true, "unlocked_by": null, "difficulty": 1, "topics": [ - "booleans", - "integers", - "logic" + "arrays", + "strings" ] }, { @@ -238,11 +237,23 @@ "text_formatting" ] }, + { + "slug": "leap", + "uuid": "7c8294ee-5924-4bf8-a72f-31d0e2d7d9a0", + "core": false, + "unlocked_by": "resistor-color", + "difficulty": 1, + "topics": [ + "booleans", + "integers", + "logic" + ] + }, { "slug": "reverse-string", "uuid": "e84c97eb-dbec-487c-b99f-ae9924e16293", "core": false, - "unlocked_by": "leap", + "unlocked_by": "resistor-color", "difficulty": 2, "topics": [ "for", @@ -254,7 +265,7 @@ "slug": "triangle", "uuid": "ed3ca73a-a0f0-46b8-8013-8b6d20758c8f", "core": false, - "unlocked_by": "leap", + "unlocked_by": "resistor-color", "difficulty": 3, "topics": [ "control_flow_conditionals", @@ -267,7 +278,7 @@ "slug": "collatz-conjecture", "uuid": "b8dacb3a-51d0-4da7-a6d2-aa29867e2b8c", "core": false, - "unlocked_by": "leap", + "unlocked_by": "resistor-color", "difficulty": 3, "topics": [ "control_flow_conditionals", diff --git a/exercises/resistor-color/.eslintrc b/exercises/resistor-color/.eslintrc new file mode 100644 index 0000000000..2e5a5079a0 --- /dev/null +++ b/exercises/resistor-color/.eslintrc @@ -0,0 +1,26 @@ +{ + "root": true, + "parser": "babel-eslint", + "parserOptions": { + "ecmaVersion": 7, + "sourceType": "module" + }, + "env": { + "es6": true, + "node": true, + "jest": true + }, + "extends": [ + "eslint:recommended", + "plugin:import/errors", + "plugin:import/warnings" + ], + "rules": { + "linebreak-style": "off", + + "import/extensions": "off", + "import/no-default-export": "off", + "import/no-unresolved": "off", + "import/prefer-default-export": "off" + } +} diff --git a/exercises/resistor-color/README.md b/exercises/resistor-color/README.md new file mode 100644 index 0000000000..9df1660637 --- /dev/null +++ b/exercises/resistor-color/README.md @@ -0,0 +1,52 @@ +# Resistor Color + +Resistors have color coded bands, where each color maps to a number. The first 2 bands of a resistor have a simple encoding scheme: each color maps to a single number. + +These colors are encoded as follows: + +- Black: 0 +- Brown: 1 +- Red: 2 +- Orange: 3 +- Yellow: 4 +- Green: 5 +- Blue: 6 +- Violet: 7 +- Grey: 8 +- White: 9 + +Mnemonics map the colors to the numbers, that, when stored as an array, happen to map to their index in the array: Better Be Right Or Your Great Big Values Go Wrong. + +More information on the color encoding of resistors can be found in the [Electronic color code Wikipedia article](https://en.wikipedia.org/wiki/Electronic_color_code) + +## Setup + +Go through the setup instructions for Javascript to +install the necessary dependencies: + +[https://exercism.io/tracks/javascript/installation](https://exercism.io/tracks/javascript/installation) + +## Requirements + +Install assignment dependencies: + +```bash +$ npm install +``` + +## Making the test suite pass + +Execute the tests with: + +```bash +$ npm test +``` + +In the test suites all tests but the first have been skipped. + +Once you get a test passing, you can enable the next one by +changing `xtest` to `test`. + +## 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/resistor-color/babel.config.js b/exercises/resistor-color/babel.config.js new file mode 100644 index 0000000000..9da4622b24 --- /dev/null +++ b/exercises/resistor-color/babel.config.js @@ -0,0 +1,14 @@ +module.exports = { + presets: [ + [ + '@babel/env', + { + targets: { + node: 'current', + }, + useBuiltIns: false, + }, + + ], + ], +}; diff --git a/exercises/resistor-color/example.js b/exercises/resistor-color/example.js new file mode 100644 index 0000000000..e578ea9024 --- /dev/null +++ b/exercises/resistor-color/example.js @@ -0,0 +1,6 @@ +export const COLORS = [ + 'black', 'brown', 'red', 'orange', 'yellow', 'green', + 'blue', 'violet', 'grey', 'white', +]; + +export const colorCode = color => COLORS.indexOf(color) diff --git a/exercises/resistor-color/package.json b/exercises/resistor-color/package.json new file mode 100644 index 0000000000..e710ca7a1e --- /dev/null +++ b/exercises/resistor-color/package.json @@ -0,0 +1,34 @@ +{ + "name": "exercism-javascript", + "version": "0.0.0", + "description": "Exercism exercises in Javascript.", + "author": "Katrina Owen", + "private": true, + "repository": { + "type": "git", + "url": "https://github.com/exercism/javascript" + }, + "devDependencies": { + "@babel/cli": "^7.2.3", + "@babel/core": "^7.4.0", + "@babel/preset-env": "^7.4.2", + "babel-eslint": "^10.0.1", + "babel-jest": "^24.5.0", + "eslint": "^5.15.3", + "eslint-plugin-import": "^2.16.0", + "jest": "^24.5.0" + }, + "jest": { + "modulePathIgnorePatterns": [ + "package.json" + ] + }, + "scripts": { + "test": "jest --no-cache ./*", + "watch": "jest --no-cache --watch ./*", + "lint": "eslint .", + "lint-test": "eslint . && jest --no-cache ./* " + }, + "license": "MIT", + "dependencies": {} +} \ No newline at end of file diff --git a/exercises/resistor-color/resistor-color.spec.js b/exercises/resistor-color/resistor-color.spec.js new file mode 100644 index 0000000000..8879b3d1c4 --- /dev/null +++ b/exercises/resistor-color/resistor-color.spec.js @@ -0,0 +1,21 @@ +import { colorCode, COLORS } from './resistor-color' + +describe('ResistorColor', () => { + describe('Color codes', () => { + test('Black', () => { + expect(colorCode("black")).toEqual(0) + }) + + xtest('White', () => { + expect(colorCode("white")).toEqual(9) + }) + + xtest('Orange', () => { + expect(colorCode("orange")).toEqual(3) + }) + }) + + xtest('Colors', () => { + expect(COLORS).toEqual(["black","brown","red","orange","yellow","green","blue","violet","grey","white"]) + }) +})