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

Add exercise: resistor-color #648

Merged
merged 6 commits 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
27 changes: 19 additions & 8 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions exercises/resistor-color/.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"
}
}
52 changes: 52 additions & 0 deletions exercises/resistor-color/README.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 14 additions & 0 deletions exercises/resistor-color/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,
},

],
],
};
6 changes: 6 additions & 0 deletions exercises/resistor-color/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const COLORS = [
'black', 'brown', 'red', 'orange', 'yellow', 'green',
'blue', 'violet', 'grey', 'white',
];

export const colorCode = color => COLORS.indexOf(color)
34 changes: 34 additions & 0 deletions exercises/resistor-color/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": {}
}
21 changes: 21 additions & 0 deletions exercises/resistor-color/resistor-color.spec.js
Original file line number Diff line number Diff line change
@@ -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"])
})
})