Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions katas/moduleDependences/README.md
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions katas/moduleDependences/get-dependencies-test.js
Original file line number Diff line number Diff line change
@@ -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([]);
});
});
3 changes: 3 additions & 0 deletions katas/moduleDependences/get-dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function getDependencies(tree) {
// ... your code here.
}