-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial commit #231
base: master
Are you sure you want to change the base?
initial commit #231
Conversation
const fromDowelRods = boardGame[fromDowel] | ||
const toDowelRods = boardGame[toDowel] | ||
|
||
if (fromDowelRods.length === 0) { | ||
console.log('Sorry, there are no dowels here to move!') | ||
return; | ||
} | ||
|
||
|
||
const moveTheRod = fromDowelRods[fromDowelRods.length - 1] | ||
|
||
|
||
|
||
if (toDowelRods.length === 0 || moveTheRod < toDowelRods[toDowelRods.length - 1]) { | ||
toDowelRods.push(fromDowelRods.pop()); | ||
console.log(`You have moved the rod ${moveTheRod} to this dowel ${fromDowel + 1}, to this dowel ${toDowel + 1}`); | ||
} else { | ||
console.log('Sorry-unfortunately, this move is now allowed. You cannot put a larger rod/disc on a smaller one. Try again.'); | ||
} | ||
|
||
towerHanoi(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align and space properly your code, this makes reading very difficult.
fromDowel = fromDowel - 1; | ||
toDowel = toDowel - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not overwrite passed params. This is a very bad practice. Always declare a new const/let
|
||
|
||
|
||
if (toDowelRods.length === 0 || moveTheRod < toDowelRods[toDowelRods.length - 1]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the only validation needed? What about preventing moving a disc from to the same peg you are moving it to?
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty spaces?
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty spaces
] | ||
|
||
function towerHanoi() { | ||
boardGame.map((dowel, index) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why map if you are not storing the map result anywhere?
correct helper is forEach, map always returns something
} | ||
|
||
|
||
const moveTheRod = fromDowelRods[fromDowelRods.length - 1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not clear what is this doing actually, name not clear
[] | ||
] | ||
|
||
function towerHanoi() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad function name, use something more declarative like drawBoard
moveDisc(1, 3); | ||
|
||
// create checkWinner function to see if player has won the game | ||
function checkWinner() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its not being used, the game doesnt check after each move if the game was won successfully.
// create checkWinner function to see if player has won the game | ||
function checkWinner() { | ||
|
||
const victorHanoi = [5, 4, 3, 2, 1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be defined on the top of the file and not recreated each time you call this function, this is a bad practice.
No description provided.