Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yitonghe00/8666ee9dba783e8af8e874ee04bb6d96 to your computer and use it in GitHub Desktop.
Save yitonghe00/8666ee9dba783e8af8e874ee04bb6d96 to your computer and use it in GitHub Desktop.
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