Created
November 20, 2016 20:54
-
-
Save towerofnix/470a32f40c51799a91dfc66b5b22dd6a to your computer and use it in GitHub Desktop.
Picks a country for you to study. (Actually, three.)
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
fetch('https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_and_their_capitals_in_native_languages') | |
.then(res => res.text()) | |
.then(resText => (new DOMParser()).parseFromString(resText, 'text/html')) | |
.then(doc => ( | |
Array.from(doc.getElementsByClassName('wikitable')) | |
.map(tbl => tbl.querySelectorAll('tr')) | |
.reduce((f, tf) => f.concat(Array.from(tf)), []) | |
.map(r => r.children[0]) | |
.map(t => t.innerText) | |
)) | |
.then(countries => { | |
const picked = [] | |
for (i = 0; i < 3; i++) { | |
picked.push(countries[Math.floor(Math.random() * countries.length)]) | |
} | |
return picked | |
}) | |
.then(picked => { | |
console.log(picked) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment