Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement resistor-colors exercise #642

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -1317,7 +1328,6 @@
"math"
]
},

{
"slug": "trinary",
"uuid": "1acf1d2d-a25e-4576-94de-0470abc872d9",
Expand Down
26 changes: 26 additions & 0 deletions exercises/resistor-colors/.eslintrc
Original file line number Diff line number Diff line change
@@ -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"
}
}
54 changes: 54 additions & 0 deletions exercises/resistor-colors/README.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 14 additions & 0 deletions exercises/resistor-colors/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
presets: [
[
'@babel/env',
{
targets: {
node: 'current',
},
useBuiltIns: false,
},

],
],
};
8 changes: 8 additions & 0 deletions exercises/resistor-colors/example.js
Original file line number Diff line number Diff line change
@@ -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);
34 changes: 34 additions & 0 deletions exercises/resistor-colors/package.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
19 changes: 19 additions & 0 deletions exercises/resistor-colors/resistor-colors.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});