refactored Scope to DRY - extracted scope tree traversal algorithm to fn

For simpler maintenance, extracted algorithm into function, instead of the current comment: `// this piece should be kept in sync with the traversal in $broadcast`