diff --git a/katas/moduleDependences/README.md b/katas/moduleDependences/README.md new file mode 100644 index 0000000..b1401a5 --- /dev/null +++ b/katas/moduleDependences/README.md @@ -0,0 +1,59 @@ +## Module Dependencies + +Write recursive function that return all dependencies (and sub-dependencies) in unique module, sort dependencies in alphabet order. +Dependencies should be displayed as * @ * version dependency, eg. `Inflection @ 1.2.6`. + +Extra Task -> * @ * allows multiple versions of the same module, but duplicates (identical versions) must be removed. + +## Arguments + +* `tree`�: tree of dependencies. In Example section you can see the structure. + +## Example + +// See the example + +```javascript + +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 + +* You can't use `for`/`while`. + +## Base + +// Your work is to implement something like in Example in JavaScript. +// With this purpose, I have defined the getDependencies function. + +```js +function getDependencies(tree) { + // ... your code here. + // NOTE: you can add some new arguments to function +} + +module.exports = getDependencies +``` + +## Recourses + +* https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Object/keys diff --git a/katas/moduleDependences/get-dependencies-test.js b/katas/moduleDependences/get-dependencies-test.js new file mode 100644 index 0000000..3e33238 --- /dev/null +++ b/katas/moduleDependences/get-dependencies-test.js @@ -0,0 +1,54 @@ +describe('module dependencies', function() { + var testTree; + + beforeEach(function() { + 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" + } + } + }, + lorem = { + "dependencies": { + "wordwrap": { + "version": "0.0.2", + "version": "1.0.2", + } + } + }, + loremEmpty = { + "dependencies": { + "wordwrap": { + } + } + } + }); + + it('should return correct array of dependencies in descending order', function() { + expect(getDependencies(loremIpsum)).toEqual([ 'inflection@1.2.6', 'optimist@0.3.7', 'wordwrap@0.0.2']); + }); + + it('should return latest version of dependency'), function() { + expect(getDependencies(lorem)).toEqual([ 'wordwrap@1.0.2']); + }); + + it('should have the same character @'), function() { + var result = getDependencies(lorem); + expect(result[0].slice(-6,-5)).toEqual('@'); + }); + + it('should return empty array if module doesn\'t have dependencies'), function() { + expect(getDependencies(loremEmpty)).toEqual([]); + }); +}); diff --git a/katas/moduleDependences/get-dependencies.js b/katas/moduleDependences/get-dependencies.js new file mode 100644 index 0000000..8fd98bb --- /dev/null +++ b/katas/moduleDependences/get-dependencies.js @@ -0,0 +1,3 @@ +function getDependencies(tree) { + // ... your code here. +}