Julio Biason
3 years ago
13 changed files with 5434 additions and 0 deletions
@ -0,0 +1,12 @@ |
|||||||
|
!.meta |
||||||
|
|
||||||
|
# Protected or generated |
||||||
|
.git |
||||||
|
.vscode |
||||||
|
|
||||||
|
# When using npm |
||||||
|
node_modules/* |
||||||
|
|
||||||
|
# Configuration files |
||||||
|
babel.config.js |
||||||
|
jest.config.js |
@ -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" |
||||||
|
} |
||||||
|
] |
||||||
|
} |
@ -0,0 +1,12 @@ |
|||||||
|
{ |
||||||
|
"blurb": "Given a year, report if it is a leap year.", |
||||||
|
"authors": ["masters3d"], |
||||||
|
"contributors": ["DFXLuna", "lukaszklis", "SleeplessByte"], |
||||||
|
"files": { |
||||||
|
"solution": ["leap.ts"], |
||||||
|
"test": ["leap.test.ts"], |
||||||
|
"example": [".meta/proof.ci.ts"] |
||||||
|
}, |
||||||
|
"source": "JavaRanch Cattle Drive, exercise 3", |
||||||
|
"source_url": "http://www.javaranch.com/leap.jsp" |
||||||
|
} |
@ -0,0 +1 @@ |
|||||||
|
{"track":"typescript","exercise":"leap","id":"a6d0a1d116ab4ea68fc1e124fd5da622","url":"https://exercism.org/tracks/typescript/exercises/leap","handle":"JBiason","is_requester":true,"auto_approve":false} |
@ -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 leap.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. |
@ -0,0 +1,45 @@ |
|||||||
|
# Leap |
||||||
|
|
||||||
|
Welcome to Leap on Exercism's TypeScript Track. |
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`. |
||||||
|
|
||||||
|
## Instructions |
||||||
|
|
||||||
|
Given a year, report if it is a leap year. |
||||||
|
|
||||||
|
The tricky thing here is that a leap year in the Gregorian calendar occurs: |
||||||
|
|
||||||
|
```text |
||||||
|
on every year that is evenly divisible by 4 |
||||||
|
except every year that is evenly divisible by 100 |
||||||
|
unless the year is also evenly divisible by 400 |
||||||
|
``` |
||||||
|
|
||||||
|
For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap |
||||||
|
year, but 2000 is. |
||||||
|
|
||||||
|
## Notes |
||||||
|
|
||||||
|
Though our exercise adopts some very simple rules, there is more to |
||||||
|
learn! |
||||||
|
|
||||||
|
For a delightful, four minute explanation of the whole leap year |
||||||
|
phenomenon, go watch [this youtube video][video]. |
||||||
|
|
||||||
|
[video]: http://www.youtube.com/watch?v=xX96xng7sAE |
||||||
|
|
||||||
|
## Source |
||||||
|
|
||||||
|
### Created by |
||||||
|
|
||||||
|
- @masters3d |
||||||
|
|
||||||
|
### Contributed to by |
||||||
|
|
||||||
|
- @DFXLuna |
||||||
|
- @lukaszklis |
||||||
|
- @SleeplessByte |
||||||
|
|
||||||
|
### Based on |
||||||
|
|
||||||
|
JavaRanch Cattle Drive, exercise 3 - http://www.javaranch.com/leap.jsp |
@ -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', |
||||||
|
], |
||||||
|
} |
@ -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', |
||||||
|
}, |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
import { isLeap } from './leap' |
||||||
|
|
||||||
|
describe('A leap year', () => { |
||||||
|
test('year not divisible by 4 in common year', () => { |
||||||
|
expect(isLeap(2015)).toBe(false) |
||||||
|
}) |
||||||
|
|
||||||
|
test('year divisible by 2, not divisible by 4 in common year', () => { |
||||||
|
expect(isLeap(1970)).toBe(false) |
||||||
|
}) |
||||||
|
|
||||||
|
test('year divisible by 4, not divisible by 100 in leap year', () => { |
||||||
|
expect(isLeap(1996)).toBe(true) |
||||||
|
}) |
||||||
|
|
||||||
|
test('year divisible by 4 and 5 is still a leap year', () => { |
||||||
|
expect(isLeap(1960)).toBe(true) |
||||||
|
}) |
||||||
|
|
||||||
|
test('year divisible by 100, not divisible by 400 in common year', () => { |
||||||
|
expect(isLeap(2100)).toBe(false) |
||||||
|
}) |
||||||
|
|
||||||
|
test('year divisible by 100 but not by 3 is still not a leap year', () => { |
||||||
|
expect(isLeap(1900)).toBe(false) |
||||||
|
}) |
||||||
|
|
||||||
|
test('year divisible by 400 in leap year', () => { |
||||||
|
expect(isLeap(2000)).toBe(true) |
||||||
|
}) |
||||||
|
|
||||||
|
test('year divisible by 400 but not by 125 is still a leap year', () => { |
||||||
|
expect(isLeap(2400)).toBe(true) |
||||||
|
}) |
||||||
|
|
||||||
|
test('year divisible by 200, not divisible by 400 in common year', () => { |
||||||
|
expect(isLeap(1800)).toBe(false) |
||||||
|
}) |
||||||
|
}) |
@ -0,0 +1,3 @@ |
|||||||
|
export function isLeap(year: number): boolean { |
||||||
|
return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
{ |
||||||
|
"name": "@exercism/typescript-leap", |
||||||
|
"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" |
||||||
|
} |
||||||
|
} |
@ -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"] |
||||||
|
} |
Loading…
Reference in new issue