Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.clear()
- console.log('x')
- var edges = [
- [ ], // 0
- [2], // 1
- [4,6], //2
- [4,5], //3
- [2,3,5], //4
- [3,4,6] //5
- ]
- var source = Rx.Observable
- .of([1,5,3,6,4,2])
- .map(() => ({
- s: [3],
- r: [1,5,6,4,2].reverse()
- }))
- .expand(({s,r}) => {
- let step = []
- s.forEach(nodeWithMsg => {
- let index = r.findIndex(x => edges[nodeWithMsg].includes(x))
- if(index != null) {
- step = [...step, ...r.splice(index, 1)]
- }
- })
- return Rx.Observable.of({
- s: s.concat(step),
- r
- })
- })
- .do(console.log)
- .filter(({r}) => r.length === 0)
- .take(1)
- var subscription = source.subscribe(
- function (x) {
- console.log('Next: %s', x);
- },
- function (err) {
- console.log('Error: %s', err);
- },
- function () {
- console.log('Completed');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement