Created
July 31, 2020 05:27
-
-
Save jamonholmgren/0d49d000966ebbfb98dca2719a253e98 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
// did we find the destination? | |
if (lowestCostNode.x === state.destX && lowestCostNode.y === state.destY) { | |
// retrace our steps back to the beginning! | |
function retrace(node, path) { | |
// did we find the origin? if so, we're done! | |
if (node.previous === undefined) return [node, ...path] | |
// not yet ... let's keep retracing our steps | |
return retrace(node.previous, [ node, ...path ]) | |
} | |
// kick off the retracing! | |
return retrace(lowestCostNode, []) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment