Created
May 4, 2022 05:42
-
-
Save yitonghe00/8666ee9dba783e8af8e874ee04bb6d96 to your computer and use it in GitHub Desktop.
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
async function locateScalpel(nest) { | |
let curr = nest.name; | |
let next = await anyStorage(nest, curr, "scalpel"); | |
while (next !== curr) { | |
curr = next; | |
next = await anyStorage(nest, curr, "scalpel"); | |
} | |
return curr; | |
} | |
/** | |
* Without async/await version | |
*/ | |
function locateScalpel2(nest) { | |
const locateHelper = (curr) => { | |
return anyStorage(nest, curr, "scalpel") | |
.then((next) =>{ | |
if (next === curr) { | |
return curr; | |
} | |
return locateHelper(next); | |
}); | |
}; | |
return locateHelper(nest.name); | |
} | |
locateScalpel(bigOak).then(console.log); | |
locateScalpel2(bigOak).then(console.log); | |
// → Butcher Shop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment