Skip to content

Commit ea90289

Browse files
RoshanjosseyrjossySleeplessByte
authored
Add exercise resistor color (#300)
* Add exercise resistor color Address issue #238 * Add entry for resitor color in config.json * Sync this exercise Co-authored-by: rjossy <[email protected]> Co-authored-by: Derk-Jan Karrenbeld <[email protected]>
1 parent fc3086d commit ea90289

12 files changed

+4626
-0
lines changed

config.json

+11
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@
5252
"logic"
5353
]
5454
},
55+
{
56+
"slug": "resistor-color",
57+
"uuid": "c6f41fd5-584c-46ca-b3c5-6a0825446bf4",
58+
"core": true,
59+
"unlocked_by": null,
60+
"difficulty": 1,
61+
"topics": [
62+
"arrays",
63+
"strings"
64+
]
65+
},
5566
{
5667
"slug": "rna-transcription",
5768
"uuid": "b4db381f-1c99-44c6-948c-c8892d77823e",
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bin/*
2+
dist/*
3+
docs/*
4+
node_modules/*
5+
production_node_modules/*
6+
test/fixtures/*
7+
tmp/*
8+
9+
babel.config.js
10+
jest.config.js

exercises/resistor-color/.eslintrc

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"project": "./tsconfig.json",
6+
"ecmaFeatures": {
7+
"jsx": true
8+
},
9+
"ecmaVersion": 2018,
10+
"sourceType": "module"
11+
},
12+
"env": {
13+
"browser": true,
14+
"es6": true
15+
},
16+
"extends": [
17+
"eslint:recommended",
18+
"plugin:@typescript-eslint/eslint-recommended",
19+
"plugin:@typescript-eslint/recommended"
20+
],
21+
"globals": {
22+
"Atomics": "readonly",
23+
"SharedArrayBuffer": "readonly"
24+
},
25+
"plugins": [
26+
"@typescript-eslint"
27+
],
28+
"rules": {
29+
// Code style not forced upon the student
30+
"@typescript-eslint/array-type": "off",
31+
32+
// Prevent bugs
33+
"@typescript-eslint/explicit-function-return-type": [
34+
"warn", {
35+
"allowExpressions": false,
36+
"allowTypedFunctionExpressions": true,
37+
"allowHigherOrderFunctions": true
38+
}
39+
],
40+
41+
// Code style not forced upon the student
42+
"@typescript-eslint/explicit-member-accessibility": "off",
43+
44+
// Code style not forced upon the student
45+
"@typescript-eslint/indent": "off",
46+
47+
"@typescript-eslint/no-inferrable-types": [
48+
"error", {
49+
"ignoreParameters": true
50+
}
51+
],
52+
53+
// Code style not forced upon the student
54+
"@typescript-eslint/member-delimiter-style": "off",
55+
56+
// Code style not forced upon the student
57+
"@typescript-eslint/no-non-null-assertion": "off",
58+
59+
// Only disallow readonly without an access modifier
60+
"@typescript-eslint/no-parameter-properties": [
61+
"warn", {
62+
"allows": [
63+
"private", "protected", "public",
64+
"private readonly", "protected readonly", "public readonly"
65+
]
66+
}
67+
],
68+
69+
// Covered by the tsc compiler (noUnusedLocals)
70+
"@typescript-eslint/no-unused-vars": "off",
71+
72+
// Prevent bugs, not styling
73+
"@typescript-eslint/no-use-before-define": [
74+
"error", {
75+
"functions": false,
76+
"typedefs": false
77+
}
78+
],
79+
80+
// Always disable base-rule
81+
"semi": "off",
82+
83+
// Code style not forced upon student
84+
"@typescript-eslint/semi": "off"
85+
}
86+
}

exercises/resistor-color/README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Resistor Color
2+
3+
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.
4+
5+
These colors are encoded as follows:
6+
7+
- Black: 0
8+
- Brown: 1
9+
- Red: 2
10+
- Orange: 3
11+
- Yellow: 4
12+
- Green: 5
13+
- Blue: 6
14+
- Violet: 7
15+
- Grey: 8
16+
- White: 9
17+
18+
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.
19+
20+
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)
21+
22+
## Setup
23+
24+
Go through the setup instructions for TypeScript to install the necessary
25+
dependencies:
26+
27+
[https://exercism.io/tracks/typescript/installation](https://exercism.io/tracks/typescript/installation)
28+
29+
## Requirements
30+
31+
Install assignment dependencies:
32+
33+
```bash
34+
$ yarn install
35+
```
36+
37+
## Making the test suite pass
38+
39+
Execute the tests with:
40+
41+
```bash
42+
$ yarn test
43+
```
44+
45+
In the test suites all tests but the first have been skipped.
46+
47+
Once you get a test passing, you can enable the next one by changing `xit` to
48+
`it`.
49+
50+
## Source
51+
52+
https://github.com/exercism/problem-specifications/issues/1458
53+
54+
## Submitting Incomplete Solutions
55+
56+
It's possible to submit an incomplete solution so you can see how others have
57+
completed the exercise.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
"@babel/preset-env",
5+
{
6+
targets: {
7+
node: "current",
8+
},
9+
useBuiltIns: "entry",
10+
corejs: 3,
11+
},
12+
],
13+
"@babel/preset-typescript",
14+
],
15+
plugins: [
16+
"@babel/proposal-class-properties",
17+
"@babel/proposal-object-rest-spread",
18+
"@babel/plugin-syntax-bigint",
19+
],
20+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
verbose: true,
3+
projects: ["<rootDir>"],
4+
testMatch: [
5+
"**/__tests__/**/*.[jt]s?(x)",
6+
"**/test/**/*.[jt]s?(x)",
7+
"**/?(*.)+(spec|test).[jt]s?(x)",
8+
],
9+
testPathIgnorePatterns: [
10+
"/(?:production_)?node_modules/",
11+
".d.ts$",
12+
"<rootDir>/test/fixtures",
13+
"<rootDir>/test/helpers",
14+
"__mocks__",
15+
],
16+
transform: {
17+
"^.+\\.[jt]sx?$": "babel-jest",
18+
},
19+
}

exercises/resistor-color/package.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "@exercism/typescript",
3+
"description": "Exercism exercises in Typescript.",
4+
"private": true,
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/exercism/typescript"
8+
},
9+
"devDependencies": {
10+
"@babel/core": "^7.12.10",
11+
"@babel/plugin-proposal-class-properties": "^7.12.1",
12+
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
13+
"@babel/plugin-syntax-bigint": "^7.8.3",
14+
"@babel/preset-env": "^7.12.10",
15+
"@babel/preset-typescript": "^7.12.7",
16+
"@types/jest": "^26.0.19",
17+
"@types/node": "^14.14.13",
18+
"@typescript-eslint/eslint-plugin": "^4.9.1",
19+
"@typescript-eslint/parser": "^4.9.1",
20+
"babel-jest": "^26.6.3",
21+
"core-js": "^3.8.1",
22+
"eslint": "^7.15.0",
23+
"eslint-plugin-import": "^2.22.1",
24+
"jest": "^26.6.3",
25+
"typescript": "^4.1.3"
26+
},
27+
"scripts": {
28+
"test": "yarn lint:types && jest --no-cache",
29+
"lint": "yarn lint:types && yarn lint:ci",
30+
"lint:types": "yarn tsc --noEmit -p .",
31+
"lint:ci": "eslint . --ext .tsx,.ts"
32+
},
33+
"dependencies": {}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const COLORS = ["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"]
2+
3+
export const colorCode = (color: string): number => COLORS.indexOf(color)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { colorCode, COLORS } from './resistor-color'
2+
3+
describe('color code', () => {
4+
it('Black', () => {
5+
expect(colorCode('black')).toEqual(0)
6+
})
7+
8+
xit('White', () => {
9+
expect(colorCode('white')).toEqual(9)
10+
})
11+
12+
xit('Orange', () => {
13+
expect(colorCode('orange')).toEqual(3)
14+
})
15+
})
16+
17+
describe('Colors', () => {
18+
xit('returns all colors', () => {
19+
expect(COLORS).toEqual(["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"])
20+
})
21+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const colorCode = () => {
2+
throw new Error('Delete this line and implement this function')
3+
}
4+
5+
export const COLORS = undefined;
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
5+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6+
"lib": ["esnext", "es2016", "es2017"], /* Specify library files to be included in the compilation. */
7+
// "allowJs": true, /* Allow javascript files to be compiled. */
8+
// "checkJs": true, /* Report errors in .js files. */
9+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
10+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
11+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
12+
// "sourceMap": true, /* Generates corresponding '.map' file. */
13+
// "outFile": "./", /* Concatenate and emit output to single file. */
14+
// "outDir": "./build", /* Redirect output structure to the directory. */
15+
// "rootDirs": ["./"], /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
16+
// "composite": true, /* Enable project compilation */
17+
// "removeComments": true, /* Do not emit comments to output. */
18+
"noEmit": true, /* Do not emit outputs. */
19+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
20+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
21+
"isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
22+
// "noEmitOnError": true, /* Do not emit outputs when compilation fails. */
23+
24+
/* Strict Type-Checking Options */
25+
"strict": true, /* Enable all strict type-checking options. */
26+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
27+
// "strictNullChecks": true, /* Enable strict null checks. */
28+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
29+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
30+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
31+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
32+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
33+
34+
/* Additional Checks */
35+
// "noUnusedLocals": true, /* Report errors on unused locals. */
36+
"noUnusedParameters": true, /* Report errors on unused parameters. */
37+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
38+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
39+
40+
/* Module Resolution Options */
41+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
42+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
43+
// "paths": { "~src/*": ["./src/*"] }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
44+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
45+
// "typeRoots": [], /* List of folders to include type definitions from. */
46+
// "types": [], /* Type declaration files to be included in compilation. */
47+
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
48+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
49+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
50+
51+
/* Source Map Options */
52+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
53+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
54+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
55+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
56+
57+
/* Experimental Options */
58+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
59+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
60+
},
61+
"compileOnSave": true,
62+
"exclude": [
63+
"node_modules"
64+
]
65+
}

0 commit comments

Comments
 (0)