-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5e040b
commit e334232
Showing
5 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"track":"javascript","exercise":"armstrong-numbers","id":"a0217a4d961c48c2beba064ccea0386d","url":"https://exercism.io/my/solutions/a0217a4d961c48c2beba064ccea0386d","handle":"rolandleth","is_requester":true,"auto_approve":false} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Armstrong Numbers | ||
|
||
An [Armstrong number](https://en.wikipedia.org/wiki/Narcissistic_number) is a number that is the sum of its own digits each raised to the power of the number of digits. | ||
|
||
For example: | ||
|
||
- 9 is an Armstrong number, because `9 = 9^1 = 9` | ||
- 10 is *not* an Armstrong number, because `10 != 1^2 + 0^2 = 1` | ||
- 153 is an Armstrong number, because: `153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153` | ||
- 154 is *not* an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190` | ||
|
||
Write some code to determine whether a number is an Armstrong number. | ||
|
||
## Setup | ||
|
||
Go through the setup instructions for Javascript to | ||
install the necessary dependencies: | ||
|
||
[https://exercism.io/tracks/javascript/installation](https://exercism.io/tracks/javascript/installation) | ||
|
||
## Requirements | ||
|
||
Install assignment dependencies: | ||
|
||
```bash | ||
$ npm install | ||
``` | ||
|
||
## Making the test suite pass | ||
|
||
Execute the tests with: | ||
|
||
```bash | ||
$ npm test | ||
``` | ||
|
||
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 `xtest` to `test`. | ||
|
||
|
||
## Source | ||
|
||
Wikipedia [https://en.wikipedia.org/wiki/Narcissistic_number](https://en.wikipedia.org/wiki/Narcissistic_number) | ||
|
||
## Submitting Incomplete Solutions | ||
It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export const validate = (number) => { | ||
if (number < 10) { | ||
return true | ||
} | ||
|
||
if (number < 100) { | ||
return false | ||
} | ||
|
||
const n = `${number}` | ||
const result = n.split("").reduce((prev, current) => { | ||
const value = parseInt(current, 10) | ||
|
||
return prev + value ** n.length | ||
}, 0) | ||
|
||
return result == number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { validate } from "./armstrong-numbers" | ||
|
||
describe("ArmstrongNumber", () => { | ||
test("Single digit numbers are Armstrong numbers", () => { | ||
const input = 5 | ||
expect(validate(input)).toBe(true) | ||
}) | ||
|
||
test("There are no 2 digit Armstrong numbers", () => { | ||
const input = 10 | ||
expect(validate(input)).toBe(false) | ||
}) | ||
|
||
test("Three digit number that is an Armstrong number", () => { | ||
const input = 153 | ||
expect(validate(input)).toBe(true) | ||
}) | ||
|
||
test("Three digit number that is not an Armstrong number", () => { | ||
const input = 100 | ||
expect(validate(input)).toBe(false) | ||
}) | ||
|
||
test("Four digit number that is an Armstrong number", () => { | ||
const input = 9474 | ||
expect(validate(input)).toBe(true) | ||
}) | ||
|
||
test("Four digit number that is not an Armstrong number", () => { | ||
const input = 9475 | ||
expect(validate(input)).toBe(false) | ||
}) | ||
|
||
test("Seven digit number that is an Armstrong number", () => { | ||
const input = 9926315 | ||
expect(validate(input)).toBe(true) | ||
}) | ||
|
||
test("Seven digit number that is not an Armstrong number", () => { | ||
const input = 9926314 | ||
expect(validate(input)).toBe(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"name": "exercism-javascript", | ||
"version": "0.0.0", | ||
"description": "Exercism exercises in Javascript.", | ||
"author": "Katrina Owen", | ||
"private": true, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/exercism/javascript" | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "^10.0.1", | ||
"babel-jest": "^23.6.0", | ||
"babel-plugin-transform-builtin-extend": "^1.1.2", | ||
"babel-preset-env": "^1.7.0", | ||
"eslint": "^5.12.1", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.15.0", | ||
"jest": "^23.6.0" | ||
}, | ||
"jest": { | ||
"modulePathIgnorePatterns": [ | ||
"package.json" | ||
] | ||
}, | ||
"babel": { | ||
"presets": [ | ||
[ | ||
"env", | ||
{ | ||
"targets": [ | ||
{ | ||
"node": "current" | ||
} | ||
] | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
[ | ||
"babel-plugin-transform-builtin-extend", | ||
{ | ||
"globals": [ | ||
"Error" | ||
] | ||
} | ||
], | ||
[ | ||
"transform-regenerator" | ||
] | ||
] | ||
}, | ||
"scripts": { | ||
"test": "jest --no-cache ./*", | ||
"watch": "jest --no-cache --watch ./*", | ||
"lint": "eslint .", | ||
"lint-test": "eslint . && jest --no-cache ./* " | ||
}, | ||
"eslintConfig": { | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"ecmaVersion": 7, | ||
"sourceType": "module" | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true, | ||
"jest": true | ||
}, | ||
"extends": "airbnb-base", | ||
"rules": { | ||
"import/no-unresolved": "off", | ||
"import/extensions": "off", | ||
"import/prefer-default-export": "off", | ||
"import/no-default-export": "off" | ||
} | ||
}, | ||
"license": "MIT", | ||
"dependencies": {} | ||
} |