Browse Source

Resistor color duo

master
Julio Biason 3 years ago
parent
commit
b3f7f3b25a
  1. 12
      typescript/resistor-color-duo/.eslintignore
  2. 23
      typescript/resistor-color-duo/.eslintrc
  3. 12
      typescript/resistor-color-duo/.exercism/config.json
  4. 1
      typescript/resistor-color-duo/.exercism/metadata.json
  5. 44
      typescript/resistor-color-duo/HELP.md
  6. 53
      typescript/resistor-color-duo/README.md
  7. 20
      typescript/resistor-color-duo/babel.config.js
  8. 19
      typescript/resistor-color-duo/jest.config.js
  9. 33
      typescript/resistor-color-duo/package.json
  10. 23
      typescript/resistor-color-duo/resistor-color-duo.test.ts
  11. 19
      typescript/resistor-color-duo/resistor-color-duo.ts
  12. 19
      typescript/resistor-color-duo/tsconfig.json
  13. 5164
      typescript/resistor-color-duo/yarn.lock

12
typescript/resistor-color-duo/.eslintignore

@ -0,0 +1,12 @@
!.meta
# Protected or generated
.git
.vscode
# When using npm
node_modules/*
# Configuration files
babel.config.js
jest.config.js

23
typescript/resistor-color-duo/.eslintrc

@ -0,0 +1,23 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2020,
"sourceType": "module"
},
"extends": "@exercism/eslint-config-typescript",
"env": {
"jest": true
},
"overrides": [
{
"files": [".meta/proof.ci.ts", ".meta/exemplar.ts", "*.test.ts"],
"excludedFiles": ["custom.test.ts"],
"extends": "@exercism/eslint-config-typescript/maintainers"
}
]
}

12
typescript/resistor-color-duo/.exercism/config.json

@ -0,0 +1,12 @@
{
"blurb": "Convert color codes, as used on resistors, to a numeric value.",
"authors": ["msomji"],
"contributors": ["EduardoBautista", "SleeplessByte"],
"files": {
"solution": ["resistor-color-duo.ts"],
"test": ["resistor-color-duo.test.ts"],
"example": [".meta/proof.ci.ts"]
},
"source": "Maud de Vries, Erik Schierboom",
"source_url": "https://github.com/exercism/problem-specifications/issues/1464"
}

1
typescript/resistor-color-duo/.exercism/metadata.json

@ -0,0 +1 @@
{"track":"typescript","exercise":"resistor-color-duo","id":"0b14018ea67d4f2fbb7d817a164d20ed","url":"https://exercism.org/tracks/typescript/exercises/resistor-color-duo","handle":"JBiason","is_requester":true,"auto_approve":false}

44
typescript/resistor-color-duo/HELP.md

@ -0,0 +1,44 @@
# Help
## Running the tests
Execute the tests with:
```bash
$ yarn test
```
## Skipped tests
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 `xit` to
`it`.
## Submitting your solution
You can submit your solution using the `exercism submit resistor-color-duo.ts` command.
This command will upload your solution to the Exercism website and print the solution page's URL.
It's possible to submit an incomplete solution which allows you to:
- See how others have completed the exercise
- Request help from a mentor
## Need to get help?
If you'd like help solving the exercise, check the following pages:
- The [TypeScript track's documentation](https://exercism.org/docs/tracks/typescript)
- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
To get help if you're having trouble, you can use one of the following resources:
- [TypeScript QuickStart](https://www.typescriptlang.org/docs/handbook/release-notes/overview.html)
- [ECMAScript 2015 Language Specification](https://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2015.pdf) (pdf)
- [Mozilla JavaScript Reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference)
- [/r/typescript](https://www.reddit.com/r/typescript) is the TypeScript subreddit.
- [StackOverflow](https://stackoverflow.com/questions/tagged/typescript) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.

53
typescript/resistor-color-duo/README.md

@ -0,0 +1,53 @@
# Resistor Color Duo
Welcome to Resistor Color Duo on Exercism's TypeScript Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Instructions
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 has a position and a numeric value.
The first 2 bands of a resistor have a simple encoding scheme: each color maps to a single 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 color names as input and output a two digit number, even if the input is more than two colors!
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
From the example above:
brown-green should return 15
brown-green-violet should return 15 too, ignoring the third color.
## Source
### Created by
- @msomji
### Contributed to by
- @EduardoBautista
- @SleeplessByte
### Based on
Maud de Vries, Erik Schierboom - https://github.com/exercism/problem-specifications/issues/1464

20
typescript/resistor-color-duo/babel.config.js

@ -0,0 +1,20 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
useBuiltIns: 'entry',
corejs: '3.17',
},
],
'@babel/preset-typescript',
],
plugins: [
'@babel/proposal-class-properties',
'@babel/proposal-object-rest-spread',
'@babel/plugin-syntax-bigint',
],
}

19
typescript/resistor-color-duo/jest.config.js

@ -0,0 +1,19 @@
module.exports = {
verbose: true,
projects: ['<rootDir>'],
testMatch: [
'**/__tests__/**/*.[jt]s?(x)',
'**/test/**/*.[jt]s?(x)',
'**/?(*.)+(spec|test).[jt]s?(x)',
],
testPathIgnorePatterns: [
'/(?:production_)?node_modules/',
'.d.ts$',
'<rootDir>/test/fixtures',
'<rootDir>/test/helpers',
'__mocks__',
],
transform: {
'^.+\\.[jt]sx?$': 'babel-jest',
},
}

33
typescript/resistor-color-duo/package.json

@ -0,0 +1,33 @@
{
"name": "@exercism/typescript-resistor-color-duo",
"version": "1.0.0",
"description": "Exercism exercises in Typescript.",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/exercism/typescript"
},
"devDependencies": {
"@babel/core": "^7.15.5",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/plugin-proposal-object-rest-spread": "^7.14.7",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/preset-env": "^7.15.4",
"@babel/preset-typescript": "^7.15.0",
"@types/jest": "^26.0.24",
"@types/node": "^14.17.14",
"@exercism/eslint-config-typescript": "^0.3.0",
"babel-jest": "^26.6.3",
"core-js": "^3.17.2",
"eslint": "^7.32.0",
"eslint-plugin-import": "^2.24.2",
"jest": "^26.6.3",
"typescript": "^4.4.2"
},
"scripts": {
"test": "yarn lint:types && jest --no-cache",
"lint": "yarn lint:types && yarn lint:ci",
"lint:types": "yarn tsc --noEmit -p .",
"lint:ci": "eslint . --ext .tsx,.ts"
}
}

23
typescript/resistor-color-duo/resistor-color-duo.test.ts

@ -0,0 +1,23 @@
import { decodedValue } from './resistor-color-duo'
describe('Resistor Colors', () => {
test('Brown and black', () => {
expect(decodedValue(['brown', 'black'])).toEqual(10)
})
test('Blue and grey', () => {
expect(decodedValue(['blue', 'grey'])).toEqual(68)
})
test('Yellow and violet', () => {
expect(decodedValue(['yellow', 'violet'])).toEqual(47)
})
test('Orange and orange', () => {
expect(decodedValue(['orange', 'orange'])).toEqual(33)
})
test('Ignore additional colors', () => {
expect(decodedValue(['green', 'brown', 'orange'])).toEqual(51)
})
})

19
typescript/resistor-color-duo/resistor-color-duo.ts

@ -0,0 +1,19 @@
let bandColors: { [key: string]: number } = {
'black': 0,
'brown': 1,
'red': 2,
'orange': 3,
'yellow': 4,
'green': 5,
'blue': 6,
'violet': 7,
'grey': 8,
'white': 9,
};
export function decodedValue(colorArray: string[]): number {
var firstBand:string = colorArray[0];
var secondBand:string = colorArray[1];
return bandColors[firstBand] * 10 + bandColors[secondBand];
}

19
typescript/resistor-color-duo/tsconfig.json

@ -0,0 +1,19 @@
{
"display": "Configuration for Node LTS",
"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"target": "es2020",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
// Because we'll be using babel
// Ensure that Babel can safely transpile files in the TypeScript project
"isolatedModules": true
},
"include": ["*", ".meta/*"],
"exclude": ["node_modules"]
}

5164
typescript/resistor-color-duo/yarn.lock

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save