Last active
August 29, 2015 14:01
-
-
Save izolate/2074f8d025270d55e96a to your computer and use it in GitHub Desktop.
[Node.js] Solution to http://letsrevolutionizetesting.com/challenge
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
/** | |
* Requirements: Node.js, npm | |
* $ npm install request-json | |
*/ | |
request = require('request-json'); | |
var client = request.newClient('http://letsrevolutionizetesting.com'); | |
var ids = []; | |
client.get('challenge', function(err, res, body) { | |
ids.push( body.follow.replace(/\D/g,'') ); | |
var get_next = function(id) { | |
client.get('challenge?id=' + id, function(err, res, body) { | |
// still following the trail? | |
if (body.follow) { | |
var follow = body.follow.replace(/\D/g, ''); | |
ids.push(follow); | |
if (ids.indexOf(follow) != -1) { | |
get_next(last_id()); | |
} | |
} | |
// success, we've reached the end! | |
else { | |
console.log('IDs collected: %d', ids.length); | |
console.log(body.message); | |
} | |
}); | |
}; | |
// get the IDs! | |
console.log('Retrieving IDs...'); | |
get_next(last_id()); | |
}); | |
function last_id() { | |
return ids[ids.length-1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment