Use functional-programming to convert a tree of parent:children objects to array
getValidParentAndChild can be rewritten as follows:

function getValidParentAndChild(list){
    return list.filter((obj) =&gt; obj.isValid)
               .map((obj) =&gt; obj.children.filter((kid) =&gt; kid.isValid)
                                         .map((kid) =&gt; toParentChildModel(obj, kid))
               .reduce((arr1, arr2) =&gt; arr1.concat(arr2));
}


The filter takes the element of the list and keeps it if the condition passed in is met. (In this case, both uses keep all the valid elements.)

map applies a function over each element of the list and returns the list of what the function returned for each element. Here it converts the list to a list of the parent-child pairs.

reduce is also called fold. These apply a two-argument over a list such that if your list was [a, b, c, d], with the function f, the reduce would return f( f( f(a, b), c), d). Here it is used to make a 2D list a 1D array.

This problem becomes more interesting if children could have children. In that case I would do the following:

function getPairsForNode(node){
    if(node.children)
       return node.children.map((child) =&gt; getPairsForNode(child))
                           .concat(node.children.map((child) =&gt; toParentChildModel(node, child))
                           .reduce((arr1, arr2) =&gt; arr1.concat(arr2));
    else return [];
}

function getValidParentAndChild(list){
    return list.filter((node) =&gt; node.isValid)
               .map(getPairsForNode)
               .reduce((arr1, arr2) =&gt; arr1.concat(arr2));
}