Skip to content

Instantly share code, notes, and snippets.

@danshearmur
Last active August 29, 2015 14:11
Show Gist options
  • Save danshearmur/f667772117d508ef1581 to your computer and use it in GitHub Desktop.
Save danshearmur/f667772117d508ef1581 to your computer and use it in GitHub Desktop.
// super naive get xhr/promise implementation only tested in chrome
function req(url) {
var x = new XMLHttpRequest();
var success;
var done;
x.onreadystatechange = function () {
if (x.readyState === 4) {
done = JSON.parse(x.responseText);
if (typeof success === 'function') success(done);
}
};
x.open('GET', url, true);
x.setRequestHeader('Accept', 'application/json');
x.send('');
return {
then: function (cb) {
if (done) return cb(done);
success = cb;
}
};
}
// callback to recurse requests until there's no follow attribute
function cb(d) {
if (d.follow) return req(d.follow).then(cb);
console.log(d);
}
// kick it all off
req('http://letsrevolutionizetesting.com/challenge').then(cb);
//"Congratulations! You've reached the end! You have passed our simple little test and we would love to hear from you. Please save the \
//code you used to a private gist, and fill out the quick application form at \
//https://jobs.lever.co/rainforest/72beda5c-d340-41aa-97a3-2f0c3f272940 (if you're an engineer) or \
// https://jobs.lever.co/rainforest/62b39e56-ec39-4266-80d3-c48b47010596 (if you're a front-end developer). We'll be in touch shortly!"
// golf score 79
//a=$.getJSON,a(location,function b(c){c.follow?a(c.follow,b):alert(c.message)});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment