diff --git a/config.json b/config.json index 1526780fc5..60ad7fc0fc 100644 --- a/config.json +++ b/config.json @@ -41,6 +41,17 @@ "strings" ] }, + { + "slug": "resistor-colors", + "uuid": "de800041-3dcc-41b9-b101-7314ff685c93", + "core": true, + "unlocked_by": null, + "difficulty": 2, + "topics": [ + "strings", + "arrays" + ] + }, { "slug": "gigasecond", "uuid": "fd7b62d4-266b-4e84-a526-bf3d47901216", @@ -1317,7 +1328,6 @@ "math" ] }, - { "slug": "trinary", "uuid": "1acf1d2d-a25e-4576-94de-0470abc872d9", diff --git a/exercises/resistor-colors/.eslintrc b/exercises/resistor-colors/.eslintrc new file mode 100644 index 0000000000..2e5a5079a0 --- /dev/null +++ b/exercises/resistor-colors/.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-colors/README.md b/exercises/resistor-colors/README.md new file mode 100644 index 0000000000..b82b2fbf08 --- /dev/null +++ b/exercises/resistor-colors/README.md @@ -0,0 +1,54 @@ +# Resistor Colors + +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-colors/babel.config.js b/exercises/resistor-colors/babel.config.js new file mode 100644 index 0000000000..9da4622b24 --- /dev/null +++ b/exercises/resistor-colors/babel.config.js @@ -0,0 +1,14 @@ +module.exports = { + presets: [ + [ + '@babel/env', + { + targets: { + node: 'current', + }, + useBuiltIns: false, + }, + + ], + ], +}; diff --git a/exercises/resistor-colors/example.js b/exercises/resistor-colors/example.js new file mode 100644 index 0000000000..83e3b56934 --- /dev/null +++ b/exercises/resistor-colors/example.js @@ -0,0 +1,8 @@ +const COLORS = [ + 'black', 'brown', 'red', 'orange', 'yellow', 'green', + 'blue', 'violet', 'grey', 'white', +]; + +const reducer = (acc, color, i) => acc + COLORS.indexOf(color) * (10 ** i); + +export const value = colors => colors.reverse().reduce(reducer, 0); diff --git a/exercises/resistor-colors/package.json b/exercises/resistor-colors/package.json new file mode 100644 index 0000000000..e710ca7a1e --- /dev/null +++ b/exercises/resistor-colors/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-colors/resistor-colors.spec.js b/exercises/resistor-colors/resistor-colors.spec.js new file mode 100644 index 0000000000..a560b34908 --- /dev/null +++ b/exercises/resistor-colors/resistor-colors.spec.js @@ -0,0 +1,19 @@ +import { value } from './resistor-colors.js'; + +describe('Resistor Colors', () => { + test('Brown and black', () => { + expect(value(['brown', 'black'])).toEqual(10); + }); + + xtest('Blue and grey', () => { + expect(value(['blue', 'grey'])).toEqual(68); + }); + + xtest('Yellow and violet', () => { + expect(value(['yellow', 'violet'])).toEqual(47); + }); + + xtest('Orange and orange', () => { + expect(value(['orange', 'orange'])).toEqual(33); + }); +});