Skip to content

Instantly share code, notes, and snippets.

@Fity
Created May 13, 2018 09:22
Show Gist options
  • Save Fity/b57eeeef667d86f13862e085c1df1689 to your computer and use it in GitHub Desktop.
Save Fity/b57eeeef667d86f13862e085c1df1689 to your computer and use it in GitHub Desktop.
flipboard challenge solution.
var s = ''
var result = ''
var step = async (x, y, last) => {
const response = await fetch(`/step?s=${s}&x=${x}&y=${y}`)
const json = await response.json()
const adjacent = json.adjacent.filter(
item => JSON.stringify(item) !== JSON.stringify(last)
)
if (json.end) {
return json.letter
}
for (let i = 0; i < adjacent.length; i++) {
const letter = await step(adjacent[i].x, adjacent[i].y, { x, y })
if (letter) {
return json.letter + letter
}
}
}
var check = async () => {
const response = await fetch(`/check?s=${s}&amp;guess=${result}`)
const json = await response.json()
return json.success
}
var begin = async () => {
const params = new URLSearchParams(location.search)
s = params.get('s')
result = await step(0, 0, { x: 0, y: 0 })
console.log('result:', result)
const bool = await check()
console.log(bool)
}
begin()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment