Skip to content

Instantly share code, notes, and snippets.

@jpoechill
Created April 10, 2017 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpoechill/185d32563667c4effe1069326cc19f35 to your computer and use it in GitHub Desktop.
Save jpoechill/185d32563667c4effe1069326cc19f35 to your computer and use it in GitHub Desktop.
HN, get all posts' kids (recursive)
var val = fetchAllKids('9153')
// console.log(val);
function fetchAllKids(link, parent){
var uniqueID = link
var localLink1 = 'https://hacker-news.firebaseio.com/v0/item/' + uniqueID + '.json?'
axios.get(localLink1, uniqueID)
.then(function (response) {
var response = response.data
// console.log(response);
if (response.kids !== undefined) {
for (let i = 0; i < response.kids.length; i++) {
var id = response.kids[i]
// console.log('Parent: ' + uniqueID);
console.log('Fetching Id: ' + id);
fetchAllKids(id, uniqueID);
}
}
// console.log("Hello");
// console.log(response.kids);
// localVal = response;
})
.catch(function (error) {
console.log(error.message);
});
// return val.data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment