Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

initial commit #231

wants to merge 1 commit into from

Conversation

areebakwas
Copy link

No description provided.

Comment on lines +21 to +41
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();

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.

Comment on lines +18 to +19
fromDowel = fromDowel - 1;
toDowel = toDowel - 1;

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]) {

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?

Comment on lines +31 to +33



Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty spaces?

Comment on lines +28 to +29


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) => {

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]

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() {

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() {

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]

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants