This commit is contained in:
2023-07-25 22:34:22 +02:00
parent 619044ad23
commit e0d01e1c8d
18 changed files with 29635 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
!.meta
# Protected or generated
.git
.vscode
# When using npm
node_modules/*
# Configuration files
.eslintrc.cjs
babel.config.cjs
jest.config.cjs
+38
View File
@@ -0,0 +1,38 @@
module.exports = {
root: true,
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
overrides: [
// Student provided files
{
files: ['*.ts'],
excludedFiles: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
extends: '@exercism/eslint-config-typescript',
},
// Exercism given tests
{
files: ['*.test.ts'],
excludedFiles: ['custom.test.ts'],
env: {
jest: true,
},
extends: '@exercism/eslint-config-typescript/maintainers',
},
// Student provided tests
{
files: ['custom.test.ts'],
env: {
jest: true,
},
extends: '@exercism/eslint-config-typescript',
},
// Exercism provided files
{
files: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
excludedFiles: ['custom.test.ts'],
extends: '@exercism/eslint-config-typescript/maintainers',
},
],
}
+21
View File
@@ -0,0 +1,21 @@
{
"authors": [
"angelikatyborska"
],
"contributors": [
"SleeplessByte"
],
"files": {
"solution": [
"darts.ts"
],
"test": [
"darts.test.ts"
],
"example": [
".meta/proof.ci.ts"
]
},
"blurb": "Write a function that returns the earned points in a single toss of a Darts game.",
"source": "Inspired by an exercise created by a professor Della Paolera in Argentina"
}
+1
View File
@@ -0,0 +1 @@
{"track":"typescript","exercise":"darts","id":"74acea877ee9498b8ce3fda662ae6659","url":"https://exercism.org/tracks/typescript/exercises/darts","handle":"briemens","is_requester":true,"auto_approve":false}
Generated Executable
+19812
View File
File diff suppressed because one or more lines are too long
+2047
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
yarnPath: .yarn/releases/yarn-3.6.0.cjs
+44
View File
@@ -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 darts.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 programming category on the forum](https://forum.exercism.org/c/programming/5)
- 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.
+42
View File
@@ -0,0 +1,42 @@
# Darts
Welcome to Darts on Exercism's TypeScript Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Instructions
Write a function that returns the earned points in a single toss of a Darts game.
[Darts][darts] is a game where players throw darts at a [target][darts-target].
In our particular instance of the game, the target rewards 4 different amounts of points, depending on where the dart lands:
- If the dart lands outside the target, player earns no points (0 points).
- If the dart lands in the outer circle of the target, player earns 1 point.
- If the dart lands in the middle circle of the target, player earns 5 points.
- If the dart lands in the inner circle of the target, player earns 10 points.
The outer circle has a radius of 10 units (this is equivalent to the total radius for the entire target), the middle circle a radius of 5 units, and the inner circle a radius of 1.
Of course, they are all centered at the same point — that is, the circles are [concentric][] defined by the coordinates (0, 0).
Write a function that given a point in the target (defined by its [Cartesian coordinates][cartesian-coordinates] `x` and `y`, where `x` and `y` are [real][real-numbers]), returns the correct amount earned by a dart landing at that point.
[darts]: https://en.wikipedia.org/wiki/Darts
[darts-target]: https://en.wikipedia.org/wiki/Darts#/media/File:Darts_in_a_dartboard.jpg
[concentric]: https://mathworld.wolfram.com/ConcentricCircles.html
[cartesian-coordinates]: https://www.mathsisfun.com/data/cartesian-coordinates.html
[real-numbers]: https://www.mathsisfun.com/numbers/real-numbers.html
## Source
### Created by
- @angelikatyborska
### Contributed to by
- @SleeplessByte
### Based on
Inspired by an exercise created by a professor Della Paolera in Argentina
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
presets: ['@exercism/babel-preset-typescript'],
plugins: [],
}
+55
View File
@@ -0,0 +1,55 @@
import { score } from './darts'
describe('Darts', () => {
it('Missed target', () => {
expect(score(-9, 9)).toEqual(0)
})
it('On the outer circle', () => {
expect(score(0, 10)).toEqual(1)
})
it('On the middle circle', () => {
expect(score(-5, 0)).toEqual(5)
})
it('On the inner circle', () => {
expect(score(0, -1)).toEqual(10)
})
it('Exactly on centre', () => {
expect(score(0, 0)).toEqual(10)
})
it('Near the centre', () => {
expect(score(-0.1, -0.1)).toEqual(10)
})
it('Just within the inner circle', () => {
expect(score(0.7, 0.7)).toEqual(10)
})
it('Just outside the inner circle', () => {
expect(score(0.8, -0.8)).toEqual(5)
})
it('Just within the middle circle', () => {
expect(score(-3.5, 3.5)).toEqual(5)
})
it('Just outside the middle circle', () => {
expect(score(-3.6, -3.6)).toEqual(1)
})
it('Just within the outer circle', () => {
expect(score(-7.0, 7.0)).toEqual(1)
})
it('Just outside the outer circle', () => {
expect(score(7.1, -7.1)).toEqual(0)
})
it('Asymmetric position between the inner and middle circles', () => {
expect(score(0.5, -4)).toEqual(5)
})
})
+7
View File
@@ -0,0 +1,7 @@
export function score(x: number, y: number): number {
const radius = Math.sqrt(x * x + y * y)
if (radius <= 1) return 10
if (radius <= 5) return 5
if (radius <= 10) return 1
return 0
}
+19
View File
@@ -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
View File
@@ -0,0 +1,33 @@
{
"name": "@exercism/typescript-darts",
"version": "1.0.0",
"description": "Exercism exercises in Typescript.",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/exercism/typescript"
},
"type": "module",
"engines": {
"node": "^18.16.0 || >=20.0.0"
},
"devDependencies": {
"@exercism/babel-preset-typescript": "^0.4.0",
"@exercism/eslint-config-typescript": "^0.5.0",
"@types/jest": "^29.5.2",
"@types/node": "~18.16.16",
"babel-jest": "^29.5.0",
"core-js": "~3.30.2",
"eslint": "^8.42.0",
"jest": "^29.5.0",
"typescript": "~5.0.4"
},
"scripts": {
"watch": "jest --no-cache --watch",
"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"
},
"packageManager": "yarn@3.6.0"
}
+28
View File
@@ -0,0 +1,28 @@
{
"display": "Configuration for Exercism TypeScript Exercises",
"compilerOptions": {
// Allows you to use the newest syntax, and have access to console.log
// https://www.typescriptlang.org/tsconfig#lib
"lib": ["ESNEXT", "dom"],
// Make sure typescript is configured to output ESM
// https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm
"module": "ES2020",
// Since this project is using babel, TypeScript may target something very
// high, and babel will make sure it runs on your local Node version.
// https://babeljs.io/docs/en/
"target": "ESNext", // ESLint doesn't support this yet: "es2022",
"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.
//
// https://babeljs.io/docs/en/babel-plugin-transform-typescript/#caveats
"isolatedModules": true
},
"include": ["*.ts", "*.tsx", ".meta/*.ts", ".meta/*.tsx"],
"exclude": ["node_modules"]
}
File diff suppressed because it is too large Load Diff