Last active
March 29, 2018 18:14
-
-
Save zurfyx/47cf03423d2349ab5dbfab7ccc56adc6 to your computer and use it in GitHub Desktop.
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
/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
#!/usr/bin/env node | |
const _ = require('lodash'); | |
/** | |
* Recursive version of fibonacci using memoize technique and lodash. | |
*/ | |
const fibonacci = _.memoize((n) => ( | |
n <= 1 ? Math.max(0, n) : fibonacci(n - 1) + fibonacci(n - 2) | |
)); | |
if (require.main == module) { | |
const n = process.argv[2]; | |
if (n === undefined) { | |
console.error(`${process.argv[0]} ${process.argv[0]} <number>`); | |
process.exit(1); | |
} | |
if (n < 0) { | |
console.error(`Enter a positive number.`); | |
process.exit(1); | |
} | |
const val = fibonacci(n); | |
console.info(`Fibonacci digit @ ${n}: ${val}`); | |
} |
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
{ | |
"name": "ngx-demo", | |
"version": "1.0.0", | |
"lockfileVersion": 1, | |
"requires": true, | |
"dependencies": { | |
"lodash": { | |
"version": "4.17.5", | |
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", | |
"integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==" | |
} | |
} | |
} |
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
{ | |
"name": "npx-demo", | |
"version": "1.0.2", | |
"description": "", | |
"main": "index.js", | |
"bin": "index.js", | |
"repository": { | |
"url": "https://gist.github.com/zurfyx/47cf03423d2349ab5dbfab7ccc56adc6" | |
}, | |
"dependencies": { | |
"lodash": "^4.17.5" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment