Created
October 7, 2017 14:43
-
-
Save irwansyahwii/91f2f279235c6481f4590ca54444702c to your computer and use it in GitHub Desktop.
Traveloka Bus Riddle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Rx from 'rxjs/Rx'; | |
let currentBus:string = ""; | |
let Bus106Interval = Rx.Observable.interval(3000).map(() => currentBus = ('106')); | |
let Bus77Interval = Rx.Observable.interval(3000).map(() => currentBus = ('77')); | |
Bus77Interval.toPromise(); | |
setTimeout(() => { | |
Bus106Interval.toPromise(); | |
}, 1000); | |
function randomDelay(bottom:number, top:number) { | |
return Math.floor( Math.random() * ( 1 + top - bottom ) ) + bottom; | |
} | |
Rx.Observable.interval(500) | |
.delay(randomDelay(1000, 3000)) | |
.map(() => { | |
if(currentBus.length > 0){ | |
console.log(`Taking bus #${currentBus}`); | |
} | |
}).toPromise(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment