Created
April 10, 2017 22:03
-
-
Save jpoechill/185d32563667c4effe1069326cc19f35 to your computer and use it in GitHub Desktop.
HN, get all posts' kids (recursive)
This file contains 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
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