TypeScript - Leap Complete

This commit is contained in:
Anthony Cicchetti 2017-09-01 23:02:28 -04:00
parent 0636a79dde
commit b75736b57b
7 changed files with 2602 additions and 0 deletions

59
typescript/leap/README.md Normal file
View file

@ -0,0 +1,59 @@
# Leap
Given a year, report if it is a leap year.
The tricky thing here is that a leap year in the Gregorian calendar occurs:
```plain
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.
If your language provides a method in the standard library that does
this look-up, pretend it doesn't exist and implement it yourself.
## 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
## Setup
Go through the setup instructions for TypeScript to
install the necessary dependencies:
http://exercism.io/languages/typescript
## Requirements
Install assignment dependencies:
```bash
$ yarn install
```
## Making the test suite pass
Execute the tests with:
```bash
$ yarn test
```
## Source
JavaRanch Cattle Drive, exercise 3 [http://www.javaranch.com/leap.jsp](http://www.javaranch.com/leap.jsp)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

View file

@ -0,0 +1,39 @@
import isLeapYear from './leap'
describe('A leap year', () => {
it('is not very common', () => {
expect(isLeapYear(2015)).toBeFalsy()
})
it('is introduced every 4 years to adjust about a day', () => {
expect(isLeapYear(2016)).toBeTruthy()
})
it('is skipped every 100 years to remove an extra day', () => {
expect(isLeapYear(1900)).toBeFalsy()
})
it('is reintroduced every 400 years to adjust another day', () => {
expect(isLeapYear(2000)).toBeTruthy()
})
describe('Additional example of a leap year that', () => {
it('is not a leap year', () => {
expect(isLeapYear(1978)).toBeFalsy()
})
it('is a common leap year', () => {
expect(isLeapYear(1992)).toBeTruthy()
})
it('is skipped every 100 years', () => {
expect(isLeapYear(2100)).toBeFalsy()
})
it('is reintroduced every 400 years', () => {
expect(isLeapYear(2400)).toBeTruthy()
})
})
})

14
typescript/leap/leap.ts Normal file
View file

@ -0,0 +1,14 @@
function isLeapYear(year: number): boolean {
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
return true
}
return false
}
return true
}
return false
}
export default isLeapYear

View file

@ -0,0 +1,36 @@
{
"name": "xtypescript",
"version": "0",
"description": "Exercism exercises in Typescript.",
"author": "",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/exercism/xtypescript"
},
"devDependencies": {},
"scripts": {
"test": "tsc --noEmit -p . && jest --no-cache",
"lint": "tsc --noEmit -p . && tslint \"*.ts?(x)\"",
"lintci": "tslint \"*.ts?(x)\" --force"
},
"dependencies": {
"@types/jest": "^20.0.0",
"@types/node": "^7.0.5",
"jest": "^20.0.4",
"ts-jest": "^20.0.6",
"tslint": "^5.4.3",
"typescript": "^2.2.1"
},
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
]
}
}

View file

@ -0,0 +1,22 @@
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitAny": true,
"strictNullChecks": true,
"preserveConstEnums": true,
"noFallthroughCasesInSwitch":true,
"noImplicitThis":true,
"noImplicitReturns":true,
"sourceMap": true,
"noEmitOnError": true,
"outDir": "./build"
},
"compileOnSave": true,
"exclude": [
"node_modules"
]
}

127
typescript/leap/tslint.json Normal file
View file

@ -0,0 +1,127 @@
{
"jsRules": {
"class-name": true,
"comment-format": [
true,
"check-space"
],
"indent": [
true,
"spaces"
],
"no-duplicate-variable": true,
"no-eval": true,
"no-trailing-whitespace": true,
"no-unsafe-finally": true,
"one-line": [
true,
"check-open-brace",
"check-whitespace"
],
"quotemark": [
false,
"double"
],
"semicolon": [
true,
"never"
],
"triple-equals": [
true,
"allow-null-check"
],
"variable-name": [
true,
"ban-keywords"
],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
]
},
"rules": {
"class-name": true,
"comment-format": [
true,
"check-space"
],
"indent": [
true,
"spaces"
],
"no-eval": true,
"no-internal-module": true,
"no-trailing-whitespace": true,
"no-unsafe-finally": true,
"no-var-keyword": true,
"one-line": [
true,
"check-open-brace",
"check-whitespace"
],
"semicolon": [
true,
"never"
],
"triple-equals": [
true,
"allow-null-check"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"variable-name": [
true,
"ban-keywords"
],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
],
"no-namespace": true,
"prefer-for-of": true,
"only-arrow-functions": [true, "allow-declarations"],
"no-var-requires": true,
"no-any": true,
"curly": true,
"forin": true,
"no-arg": true,
"label-position": true,
"no-conditional-assignment": true,
"no-console": [true, "log", "error"],
"no-construct": true,
"no-duplicate-variable": true,
"no-empty": true,
"no-invalid-this": [true, "check-function-in-method"],
"no-misused-new": true,
"no-null-keyword": true,
"no-string-literal": true,
"radix": true,
"typeof-compare": true,
"use-isnan": true,
"prefer-const": true,
"array-type": [true, "array-simple"],
"arrow-parens": true,
"new-parens": true,
"no-consecutive-blank-lines": [true,1],
"no-parameter-properties": true,
"no-unnecessary-initializer": true,
"object-literal-shorthand": true,
"object-literal-key-quotes": [true, "as-needed"]
}
}

2305
typescript/leap/yarn.lock Normal file

File diff suppressed because it is too large Load diff