Skip to content

Instantly share code, notes, and snippets.

@jimmycrequer
Created November 30, 2019 07:34
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 jimmycrequer/c845f1e82dbfda62c61b736b9469f542 to your computer and use it in GitHub Desktop.
Save jimmycrequer/c845f1e82dbfda62c61b736b9469f542 to your computer and use it in GitHub Desktop.
geography-guessCountryFromNeighbors
async function guessCountryFromNeighbors() {
await session
.run(`
MATCH (c:Country)-[:IS_NEIGHBOR_OF]-(n:Country)
WITH c.name AS country, collect(n.name) AS neighbors
RETURN country, neighbors
`)
.then(res => {
const i = Math.round(Math.random() * res.records.length - 1)
const country = res.records[i].get('country')
const neighbors = res.records[i].get('neighbors')
const answer = readlineSync.question(`Which country is bordered by ${neighbors}?\n> `)
if (answer == country)
console.log('\x1b[32m%s\x1b[0m', 'Correct!')
else
console.log('\x1b[33m%s\x1b[0m', `Wrong! The answer is ${country}.`)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment