Every node appears once as an id , and every node except for the root appears once in a sum . So if we subtract all the sums from all the ids , we 're left with the root id.
let root = 0 ; nodeList . forEach ( element => root += ( Number ( element [ 0 ] ) - Number ( element [ 1 ] ) ) ) ; return root ; }