function bfs(list, cb) { while (list.length > 0) { let i = list.find(cb); if (i) return i; list = list.map(i => i.cn || []).flat(); } }