Created
          April 17, 2018 18:53 
        
      - 
      
- 
        Save mcshiz/4f5164271c69ddc556dd0d1b710e7b4a to your computer and use it in GitHub Desktop. 
    Answer
  
        
  
    
      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
    
  
  
    
  | const request = require('request'); | |
| const Rx = require('rxjs'); | |
| const { expand } = require('rxjs/operators'); | |
| const { empty } = require('rxjs/observable/empty'); | |
| const URL = 'https://letsrevolutionizetesting.com/challenge'; | |
| let makeHttpCall = (url = URL) => { | |
| return new Promise((resolve, reject) => { | |
| request.get(url, {json: true}, (e, res, body) => { | |
| if(e) { | |
| reject(e) | |
| } | |
| resolve(res) | |
| }) | |
| }) | |
| } | |
| const calls = Rx.Observable.fromPromise(makeHttpCall(URL)); | |
| let ids = calls.pipe( | |
| expand(x => { | |
| if(typeof x === 'object' && x.body.hasOwnProperty('follow')) { | |
| return makeHttpCall(x.body.follow) | |
| } | |
| console.log('Followed Until End:' + x.body.message) | |
| return empty() | |
| }) | |
| ).takeWhile(x => x.hasOwnProperty('body')) | |
| ids.subscribe( | |
| (x) => { | |
| if(typeof x === 'string') { | |
| console.log('done', x) | |
| } | |
| console.log('Following...') | |
| }, | |
| (e) => { | |
| console.log('Error', e) | |
| }, | |
| () => { | |
| console.log('Yay all done!') | |
| } | |
| ) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment