Using a recursive function in a for loop , how do i translate from python to dart

Viewed 41
def count_leaves(tree):
  if is_leaf(tree)://boolean
    return 1
  else:
    branch_counts = [count_leaves(b) for b in branches(tree)]//branches function returns list
    return sum(branch_counts)

This is the python code

Basically the for loop checks each tree's branch if its a leaf of the tree, if its a leaf it returns 1 into a list and returns the total sum of all leafs.

How do i convert this into dart?

I am not sure which methods to be using to convert this sort of code into dart. I tried the where and forEach method but can't seem to get the syntax right.

0 Answers
Related