Created
May 13, 2018 09:22
-
-
Save Fity/b57eeeef667d86f13862e085c1df1689 to your computer and use it in GitHub Desktop.
flipboard challenge solution.
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
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}&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