Perhaps I’m not understanding correctly, but I’ve gone ahead and ran the following on other editors (jsFiddle, codepen) and I get the desired result, however when I run this code in RunKit- I get a Promise object- not a console log like I want.
var terms = ['Brainf**k', 'Velato', 'Ook!'];
function get(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('get', url);
xhr.addEventListener('readystatechange', function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log('successful ... should call callback ... ');
callback(null, JSON.parse(xhr.responseText));
} else {
console.log('error ... callback with error data ... ');
callback(xhr, null);
}
}
});
xhr.send();
}
function getPromise(url) {
return new Promise(function (resolve, reject) {
get(url, function (err, result) {
if (err) reject(err);
else resolve(result);
});
});
}
var promises = terms.map(function (term) {
return getPromise('https://api.github.com/search/repositories?q=' + term);
});
Promise.all(promises).then(function (data) {
console.log(data);
});