Created
June 28, 2017 10:51
-
-
Save pdewouters/a1e52bafd98b7ce2c7599070b3403b36 to your computer and use it in GitHub Desktop.
recursion
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
# Task | |
Implement a recursive function that returns all of the unique dependencies, and sub-dependencies of a module, sorted alphabetically. Dependencies should be printed as dependency@version e.g. 'inflection@1.2.6'. | |
Multiple versions of the same module are allowed, but duplicates modules of the same version should be removed. | |
## Arguments: | |
* tree: A dependency tree. See below for an example of the structure. | |
## Example | |
var loremIpsum = { | |
"name": "lorem-ipsum", | |
"version": "0.1.1", | |
"dependencies": { | |
"optimist": { | |
"version": "0.3.7", | |
"dependencies": { | |
"wordwrap": { | |
"version": "0.0.2" | |
} | |
} | |
}, | |
"inflection": { | |
"version": "1.2.6" | |
} | |
} | |
} | |
getDependencies(loremIpsum) // => [ 'inflection@1.2.6', 'optimist@0.3.7', 'wordwrap@0.0.2' ] | |
## Conditions: | |
* Do not use any for/while loops. | |
## Boilerplate | |
function getDependencies(tree) { | |
// SOLUTION GOES HERE | |
// Note: Feel free to add additional arguments | |
// to this function for use with recursive calls. | |
// Or not! There are many ways to recurse. | |
} | |
module.exports = getDependencies | |
## Resources | |
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys | |
» To print these instructions again, run: functional-javascript print | |
» To execute your program in a test environment, run: functional-javascript run program.js | |
» To verify your program, run: functional-javascript verify program.js | |
» For help run: functional-javascript help |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment