Created
January 20, 2017 18:41
-
-
Save s00d/f19e36cfb66ddd6fd535ed9a95acf3bd to your computer and use it in GitHub Desktop.
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
class honoiClass { | |
isValidMove(sIdx, eIdx, startSelect, endSelect) { | |
if(startSelect > this.state.numDisks - 1 || endSelect < 0) return false; | |
if (this.state.stacks[sIdx][startSelect] === 0) { | |
return this.isValidMove(sIdx, eIdx, startSelect + 1, endSelect); | |
} else if (this.state.stacks[eIdx][endSelect] !== 0) { | |
if (this.state.stacks[sIdx][startSelect] < this.state.stacks[eIdx][endSelect]) { | |
return this.isValidMove(sIdx, eIdx, startSelect, endSelect-1); | |
} else { | |
return false; | |
} | |
} else return {start: startSelect, end: endSelect}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment