Simple dfs traversal in js