From e6030276360c49c31ca7201c3c6b8396ec037b0f Mon Sep 17 00:00:00 2001 From: Derk-Jan Karrenbeld Date: Tue, 26 Mar 2019 16:31:34 +0100 Subject: [PATCH 1/6] Add exercise: resistor-color --- config.json | 11 ++++ exercises/resistor-color/.eslintrc | 26 +++++++++ exercises/resistor-color/README.md | 54 +++++++++++++++++++ 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 | 27 ++++++++++ 7 files changed, 172 insertions(+) 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..a13ed98466 100644 --- a/config.json +++ b/config.json @@ -30,6 +30,17 @@ "logic" ] }, + { + "slug": "resistor-color", + "uuid": "53be6837-c224-45f1-bff3-d7f74d6285ce", + "core": true, + "unlocked_by": "leap", + "difficulty": 1, + "topics": [ + "arrays", + "strings" + ] + }, { "slug": "gigasecond", "uuid": "fd7b62d4-266b-4e84-a526-bf3d47901216", 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..0807fd48e2 --- /dev/null +++ b/exercises/resistor-color/README.md @@ -0,0 +1,54 @@ +# Resistor Color + +If you want to build something using a Raspberry Pi, you'll probably use _resistors_. For this exercise, you need to know two things about them: + +* Each resistor has a resistance value. +* Resistors are small - so small in fact that if you printed the resistance value on them, it would be hard to read. +To get around this problem, manufacturers print color-coded bands onto the resistors to denote their resistance values. Each band acts as a digit of a number. For example, if they printed a brown band (value 1) followed by a green band (value 5), it would translate to the number 15. + +In this exercise, you are going to create a helpful program so that you don't have to remember the values of the bands. The program will take two colors as input, and output the correct number. + +The band 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 + +## 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..3e3f826528 --- /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 value = 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..a392672767 --- /dev/null +++ b/exercises/resistor-color/resistor-color.spec.js @@ -0,0 +1,27 @@ +import { colorCode, COLORS } from './resistor-color.js' + +describe('Color codes', () => { + describe('Black', () => { + xtest('Black', () => { + expect(colorCode("black")).toEqual(0) + }) + }) + + describe('White', () => { + xtest('White', () => { + expect(colorCode("white")).toEqual(9) + }) + }) + + describe('Orange', () => { + xtest('Orange', () => { + expect(colorCode("orange")).toEqual(3) + }) + }) +}) + +describe('Colors', () => { + xtest('Colors', () => { + expect(COLORS).toEqual(["black","brown","red","orange","yellow","green","blue","violet","grey","white"]) + }) +}) From 72d1e7c2cee174693b39a0e6adb51bc5249529c9 Mon Sep 17 00:00:00 2001 From: Derk-Jan Karrenbeld Date: Tue, 26 Mar 2019 16:33:45 +0100 Subject: [PATCH 2/6] Replace leap as core --- config.json | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/config.json b/config.json index a13ed98466..31d334aa08 100644 --- a/config.json +++ b/config.json @@ -18,23 +18,11 @@ "text_formatting" ] }, - { - "slug": "leap", - "uuid": "7c8294ee-5924-4bf8-a72f-31d0e2d7d9a0", - "core": true, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "booleans", - "integers", - "logic" - ] - }, { "slug": "resistor-color", "uuid": "53be6837-c224-45f1-bff3-d7f74d6285ce", "core": true, - "unlocked_by": "leap", + "unlocked_by": null, "difficulty": 1, "topics": [ "arrays", @@ -249,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", @@ -265,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", @@ -278,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", From 4e6fe9708ce1aab18c628a2f046281060636493a Mon Sep 17 00:00:00 2001 From: Derk-Jan Karrenbeld Date: Tue, 26 Mar 2019 16:43:19 +0100 Subject: [PATCH 3/6] Fix example export --- exercises/resistor-color/example.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/resistor-color/example.js b/exercises/resistor-color/example.js index 3e3f826528..e578ea9024 100644 --- a/exercises/resistor-color/example.js +++ b/exercises/resistor-color/example.js @@ -3,4 +3,4 @@ export const COLORS = [ 'blue', 'violet', 'grey', 'white', ]; -export const value = color => COLORS.indexOf(color) +export const colorCode = color => COLORS.indexOf(color) From 9e27b688ddb2c4736e4b6d13b402b79ef3d30ac9 Mon Sep 17 00:00:00 2001 From: Derk-Jan Karrenbeld Date: Tue, 26 Mar 2019 17:11:00 +0100 Subject: [PATCH 4/6] Remove doubly nested test <> description --- exercises/resistor-color/resistor-color.spec.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/exercises/resistor-color/resistor-color.spec.js b/exercises/resistor-color/resistor-color.spec.js index a392672767..deed8b1112 100644 --- a/exercises/resistor-color/resistor-color.spec.js +++ b/exercises/resistor-color/resistor-color.spec.js @@ -1,26 +1,20 @@ import { colorCode, COLORS } from './resistor-color.js' -describe('Color codes', () => { - describe('Black', () => { - xtest('Black', () => { +describe('ResistorColor', () => { + describe('Color codes', () => { + test('Black', () => { expect(colorCode("black")).toEqual(0) }) - }) - describe('White', () => { xtest('White', () => { expect(colorCode("white")).toEqual(9) }) - }) - describe('Orange', () => { xtest('Orange', () => { expect(colorCode("orange")).toEqual(3) }) }) -}) -describe('Colors', () => { xtest('Colors', () => { expect(COLORS).toEqual(["black","brown","red","orange","yellow","green","blue","violet","grey","white"]) }) From b2d1f7eba22297d9a21aa2fd24f3bf8fe31e1254 Mon Sep 17 00:00:00 2001 From: Derk-Jan Karrenbeld Date: Tue, 26 Mar 2019 19:12:10 +0100 Subject: [PATCH 5/6] Fix description --- exercises/resistor-color/README.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/exercises/resistor-color/README.md b/exercises/resistor-color/README.md index 0807fd48e2..9df1660637 100644 --- a/exercises/resistor-color/README.md +++ b/exercises/resistor-color/README.md @@ -1,14 +1,8 @@ # Resistor Color -If you want to build something using a Raspberry Pi, you'll probably use _resistors_. For this exercise, you need to know two things about them: +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. -* Each resistor has a resistance value. -* Resistors are small - so small in fact that if you printed the resistance value on them, it would be hard to read. -To get around this problem, manufacturers print color-coded bands onto the resistors to denote their resistance values. Each band acts as a digit of a number. For example, if they printed a brown band (value 1) followed by a green band (value 5), it would translate to the number 15. - -In this exercise, you are going to create a helpful program so that you don't have to remember the values of the bands. The program will take two colors as input, and output the correct number. - -The band colors are encoded as follows: +These colors are encoded as follows: - Black: 0 - Brown: 1 @@ -21,6 +15,10 @@ The band colors are encoded as follows: - 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 From 55670aad1e7459c1e035166dc6f5e19a6438f211 Mon Sep 17 00:00:00 2001 From: Derk-Jan Karrenbeld Date: Tue, 26 Mar 2019 19:12:35 +0100 Subject: [PATCH 6/6] Remove extension from import --- exercises/resistor-color/resistor-color.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/resistor-color/resistor-color.spec.js b/exercises/resistor-color/resistor-color.spec.js index deed8b1112..8879b3d1c4 100644 --- a/exercises/resistor-color/resistor-color.spec.js +++ b/exercises/resistor-color/resistor-color.spec.js @@ -1,4 +1,4 @@ -import { colorCode, COLORS } from './resistor-color.js' +import { colorCode, COLORS } from './resistor-color' describe('ResistorColor', () => { describe('Color codes', () => {