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
de45e47
commit d4ea89f
Showing
5 changed files
with
65 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 @@ | ||
node_modules/ |
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,12 @@ | ||
## Requirements | ||
[Node.js](https://github.com/nodejs/node) installed | ||
|
||
## Running | ||
|
||
```bash | ||
# Install dependencies | ||
npm i | ||
|
||
# Run | ||
npm start | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 @@ | ||
{ | ||
"name": "vinibeloni", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "reverse.js", | ||
"dependencies": { | ||
"bignumber.js": "^9.0.0" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
"start": "node reverse.js" | ||
}, | ||
"author": "vinibeloni", | ||
"license": "ISC" | ||
} |
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,24 @@ | ||
/********* BIG NUMBERS *********/ | ||
const bigNumber = require('bignumber.js'); | ||
|
||
Number.__proto__.toLong = n => bigNumber(n.toString(32), 32).toString(10) | ||
|
||
Number.__proto__.isLong = n => n.toString(32).length > 16 | ||
/*******************************/ | ||
|
||
//while (list.length > 0) { result.push(list.pop()) } | ||
const reverseValue = n => n.toString().split('').reverse().join('') | ||
|
||
const reverseAction = (validate, transform, n) => validate(n) ? reverseValue(transform(n)) : null | ||
|
||
const reverse = n => | ||
reverseAction(Number.isLong, Number.toLong, n) || | ||
reverseAction(Number.isInteger, n => n, n) || | ||
'erro' | ||
|
||
const formatInput = value => Number.isLong(value) ? Number.toLong(value) : value | ||
|
||
const inputs = [1234, 12, 0, 6641112222223333333345678901118, 'lalala'] | ||
inputs.forEach((n, i) => { | ||
console.log(`Input: '${formatInput(n)}'\nOutput: '${reverse(n)}'\n`) | ||
}) |