Open BenjaminVerble opened 8 years ago
function getDependencies(tree){
var arr = [];
var tempArr = [];
var hasit = false
var tempResult = '';
var k;
if ( tree == undefined ){
return
}
if ( tree.hasOwnProperty('dependencies')){
hasit = true
var obj = tree['dependencies'];
for ( j in tree['dependencies'] ){
tempResult = j + '@' + obj[j].version
tempArr = getDependencies(obj[j])
if ( tempArr.length > 0 ){
arr = tempArr.concat(arr);
}
arr.push(tempResult);
}
}else{
}
return arr
}
module.exports = getDependencies
Hi Benjamin, I didn't do that yet, but if I understood your question you can use reduce, take a look on my repo concatAll (https://github.com/abdalla/concatAll/blob/master/index.js) I'm using recursion stuff.
Hope it helps you.
@abdalla : thanks!
worked on this with a friend. our understanding was that we could not use for loops (which we thought would exclude forEach as well)
it's a little ugly. does anyone have a recursion-only version that is easier to understand?