-
Notifications
You must be signed in to change notification settings - Fork 0
/
16.js
29 lines (26 loc) · 942 Bytes
/
16.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function getDependencies(tree) {
var dict = [];
function _getDep(obj, dict){
obj&& obj.dependencies&& Object.keys(obj.dependencies).forEach(function(v,i){
dict.indexOf(v + "@" + obj.dependencies[v].version) === -1 && dict.push(v + "@" + obj.dependencies[v].version);
obj.dependencies[v].dependencies && _getDep(obj.dependencies[v], dict);
})
}
_getDep(tree, dict);
return dict.sort();
}
module.exports = getDependencies
// official answer
//function getDependencies(mod, result) {
// result = result || []
// var dependencies = mod && mod.dependencies || []
// Object.keys(dependencies).forEach(function(dep) {
// var key = dep + '@' + mod.dependencies[dep].version
// if (result.indexOf(key) === -1) result.push(key)
// getDependencies(mod.dependencies[dep], result)
// })
// return result.sort()
//}
//
//module.exports = getDependencies
//