Conversation
There was a problem hiding this comment.
Nice logic here, but a couple things need work. When you check for something like if (array.pop()) you are changing the array, but not saving what is popped. Also, the isLegal() function should have been checked in the if statement to determine if the movePiece() function should have been called. Pretty clean syntax, just some notes here and there.
| // Your code here | ||
| // movePiece should use array method and dot method to select last index and grab it through push and pop | ||
| const movePiece = (startStack, endStack) => { | ||
| stacks[endStack].push(stacks[startStack].pop()); |
|
|
||
| // Hierarchy of logic, if the stack has nothing in it, legal move, else the starting index popped should be less then the pop of the end stack. Or else move will not work. | ||
| const isLegal = (startStack, endStack) => { | ||
| if (stacks[endStack].length === 0) { |
| const isLegal = (startStack, endStack) => { | ||
| if (stacks[endStack].length === 0) { | ||
| return true; | ||
| } else if (stacks[startStack].pop() < stacks[endStack].pop()) { |
There was a problem hiding this comment.
.pop() changes the array, we just want to check the value of the last item in the stack if there is one ( array[array.length - 1] ).
| // use previous functions to put game together | ||
| // if move function is valid run call back legal function, if nothing else run win function. | ||
| const towersOfHanoi = (startStack, endStack) => { | ||
| if (movePiece(startStack, endStack)) { |
There was a problem hiding this comment.
movePiece() doesn't check anything, it moves pieces. Here, you're moving the pieces, and since movePiece will return undefines, isLegal won't even run.
Checkpoint Rubric
This is the rubric that your instructor will use to grade your checkpoints. Please do not edit.
Checkpoint 1
Checkpoint 2
Checkpoint 3