From a6e2e0c0f20633bf7dc94837813e5e356473af8c Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Sat, 27 Oct 2018 12:47:50 -0500 Subject: [PATCH 01/10] First commit --- 03week/towersOfHanoi.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 3cf6df049..2e9b3a22f 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -35,8 +35,7 @@ function checkForWin() { } function towersOfHanoi(startStack, endStack) { - // Your code here - + // let it begin! } function getPrompt() { From 7fc7cc2ed00f0ddb859712d8c099329f008a1236 Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Sat, 27 Oct 2018 13:28:04 -0500 Subject: [PATCH 02/10] Initial comments and logical function --- 03week/towersOfHanoi.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 2e9b3a22f..68ac2cd46 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -25,19 +25,38 @@ function movePiece() { } function isLegal() { - // Your code here + } + + + function checkForWin() { // Your code here } + // let it begin! + // We get user input from where they want to take from to where they want to put to (startStack, endStack) + // We see if this is a legal move isLegal()T/F + // if so we move the peiece movePiece() + // We see if this condition gives them a win (all stacked up properly on stack c) checkForWin()T/F + // After they win reset the game + // self challenge add harder difficulty by adding a disk after reset + // add turn counter and give user feed back on what a perfect game is compared to theirs function towersOfHanoi(startStack, endStack) { - // let it begin! + + if(isLegal(startStack, endStack)){ + movePiece(startStack, endStack) + if(checkForWin()){ + resetGame(); + } + } } + + function getPrompt() { printStacks(); rl.question('start stack: ', (startStack) => { @@ -59,6 +78,12 @@ if (typeof describe === 'function') { }); }); + describe('#isLegal()', () => { + it('Should disallow invalid inputs', () => { + assert.equal(isLegal('dog', 'b'), false); + }); + }); + describe('#isLegal()', () => { it('should not allow an illegal move', () => { stacks = { @@ -79,9 +104,9 @@ if (typeof describe === 'function') { }); describe('#checkForWin()', () => { it('should detect a win', () => { - stacks = { a: [], b: [4, 3, 2, 1], c: [] }; + stacks = { a: [], b: [], c: [4, 3, 2, 1] }; assert.equal(checkForWin(), true); - stacks = { a: [1], b: [4, 3, 2], c: [] }; + stacks = { a: [1], b: [], c: [4, 3, 2] }; assert.equal(checkForWin(), false); }); }); From 9f1ad6f1812d5d25e9b7088d4d11add319964efa Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Sat, 27 Oct 2018 16:27:46 -0500 Subject: [PATCH 03/10] Major componates built --- 03week/towersOfHanoi.js | 96 +++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 23 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 68ac2cd46..e66177a3c 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -8,9 +8,9 @@ const rl = readline.createInterface({ }); let stacks = { - a: [4, 3, 2, 1], + a: [ 1], b: [], - c: [] + c: [4, 3, 2] }; function printStacks() { @@ -19,23 +19,51 @@ function printStacks() { console.log("c: " + stacks.c); } -function movePiece() { - // Your code here - +function movePiece(startStack, endStack) { + console.log("When I move you move *just like that*") + stacks[endStack].push(stacks[startStack].pop()); } -function isLegal() { - - +function isLegal(startStack, endStack) { + const startLength = stacks[startStack].length; + const endLength = stacks[endStack].length; + const startLastElement = stacks[startStack][startLength-1] + const endLastElement = stacks[endStack][endLength-1] + // console.log("Start Length " + startLength + " and last value " + startLastElement); + // console.log("End Length " + endLength + " and last value " + endLastElement); + if(startLength > 0){ + // and we don't want to try and pop from an empty array so this is a stopgap measure + if(endLength == 0 || endLastElement>=startLastElement){ + // now we do the normal tower of hanoi size comparison + return true; + } + } } - - +const validLetter = (letterInput) =>{ + switch(letterInput.toLowerCase()){ + case "a": + case "b": + case "c": + // console.log("valid letter"); + return true; + default: + return false; + } +} function checkForWin() { - // Your code here + if(stacks["a"].length == 0 && stacks["b"].length == 0){ + return true; + } +} +const resetGame = () => { + while(stacks['c'].length>0){ + stacks['a'].push(stacks['c'].shift()); + } } + // let it begin! // We get user input from where they want to take from to where they want to put to (startStack, endStack) // We see if this is a legal move isLegal()T/F @@ -46,12 +74,23 @@ function checkForWin() { // add turn counter and give user feed back on what a perfect game is compared to theirs function towersOfHanoi(startStack, endStack) { - - if(isLegal(startStack, endStack)){ - movePiece(startStack, endStack) - if(checkForWin()){ - resetGame(); + if(validLetter(startStack)&&validLetter(endStack)){ + if(isLegal(startStack, endStack)){ + if (startStack.toLowerCase() != endStack.toLowerCase()){ + movePiece(startStack, endStack) + if(checkForWin()){ + console.log("You win, you rock at computer science!") + resetGame(); + } + }else{ + console.log("Dude, move the peice don't fondle it") + } + }else{ + console.log("Not valid move, can't move bigger numbers on top of smaller numbers and can't move empty rows at all!") } + }else{ + console.log("Invalid letter") + } } @@ -71,19 +110,29 @@ function getPrompt() { if (typeof describe === 'function') { - describe('#towersOfHanoi()', () => { - it('should be able to move a block', () => { - towersOfHanoi('a', 'b'); - assert.deepEqual(stacks, { a: [4, 3, 2], b: [1], c: [] }); - }); - }); +// new - describe('#isLegal()', () => { + describe('#validLetter()', () => { it('Should disallow invalid inputs', () => { assert.equal(isLegal('dog', 'b'), false); + assert.equal(isLegal('a', 'even bigger dog'), false); + }); + }); + + describe('#resetGame()', () => { + it('Should correctly reset stacks', () => { + assert.deepEqual(stacks, { a: [4, 3, 2, 1], b: [], c: [] }); }); }); + +//new + describe('#towersOfHanoi()', () => { + it('should be able to move a block', () => { + towersOfHanoi('a', 'b'); + assert.deepEqual(stacks, { a: [4, 3, 2], b: [1], c: [] }); + }); + }); describe('#isLegal()', () => { it('should not allow an illegal move', () => { stacks = { @@ -108,6 +157,7 @@ if (typeof describe === 'function') { assert.equal(checkForWin(), true); stacks = { a: [1], b: [], c: [4, 3, 2] }; assert.equal(checkForWin(), false); + // I changed your victory condition to rod C }); }); From bb384e0f9d5a11aad1199cb51b0d29733c1d5ae1 Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Sat, 27 Oct 2018 17:11:58 -0500 Subject: [PATCH 04/10] Final set of major and minor changes and comments --- 03week/towersOfHanoi.js | 55 +++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index e66177a3c..223d277b4 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -8,9 +8,9 @@ const rl = readline.createInterface({ }); let stacks = { - a: [ 1], + a: [4, 3, 2, 1], b: [], - c: [4, 3, 2] + c: [] }; function printStacks() { @@ -20,21 +20,22 @@ function printStacks() { } function movePiece(startStack, endStack) { - console.log("When I move you move *just like that*") + // console.log("When I move you move *just like that*") stacks[endStack].push(stacks[startStack].pop()); } function isLegal(startStack, endStack) { const startLength = stacks[startStack].length; const endLength = stacks[endStack].length; - const startLastElement = stacks[startStack][startLength-1] - const endLastElement = stacks[endStack][endLength-1] + const startLastElement = stacks[startStack][startLength - 1]; + const endLastElement = stacks[endStack][endLength - 1]; // console.log("Start Length " + startLength + " and last value " + startLastElement); // console.log("End Length " + endLength + " and last value " + endLastElement); - if(startLength > 0){ - // and we don't want to try and pop from an empty array so this is a stopgap measure + if (startLength > 0) { + // we don't want to try and pop from an empty array so this is a stopgap measure if(endLength == 0 || endLastElement>=startLastElement){ // now we do the normal tower of hanoi size comparison + // if where we are going is empty, cool. If the bigger one is one bottom, cool return true; } } @@ -70,14 +71,18 @@ const resetGame = () => { // if so we move the peiece movePiece() // We see if this condition gives them a win (all stacked up properly on stack c) checkForWin()T/F // After they win reset the game - // self challenge add harder difficulty by adding a disk after reset + // self challenge: add harder difficulty by adding a disk after reset // add turn counter and give user feed back on what a perfect game is compared to theirs function towersOfHanoi(startStack, endStack) { - if(validLetter(startStack)&&validLetter(endStack)){ - if(isLegal(startStack, endStack)){ - if (startStack.toLowerCase() != endStack.toLowerCase()){ - movePiece(startStack, endStack) + const formatedStart = startStack.toLowerCase(); + const formatedEnd = endStack.toLowerCase(); + + + if(validLetter(formatedStart) && validLetter(formatedEnd)){ + if(isLegal(formatedStart, formatedEnd)){ + if (formatedStart != formatedEnd){ + movePiece(formatedStart, formatedEnd); if(checkForWin()){ console.log("You win, you rock at computer science!") resetGame(); @@ -111,16 +116,28 @@ function getPrompt() { if (typeof describe === 'function') { // new - +// note: For my functions I wasn't returning false values, only undefines. For whatever reason +// mocha will fail the test when it tests for false and sees undefined. +// i modified the tests to undefined, though this feels like a poor solution. +// will update them with your recomendations if you have any. describe('#validLetter()', () => { it('Should disallow invalid inputs', () => { - assert.equal(isLegal('dog', 'b'), false); - assert.equal(isLegal('a', 'even bigger dog'), false); + assert.equal(validLetter('dog'), false); + }); + }); + describe('#validLetter()', () => { + it('Shoudl allow for upper case of letters', () => { + assert.equal(validLetter('B'), true); }); }); - describe('#resetGame()', () => { it('Should correctly reset stacks', () => { + stacks = { + a: [], + b: [], + c: [4, 3, 2, 1] + }; + resetGame(); assert.deepEqual(stacks, { a: [4, 3, 2, 1], b: [], c: [] }); }); }); @@ -140,7 +157,7 @@ if (typeof describe === 'function') { b: [1], c: [] }; - assert.equal(isLegal('a', 'b'), false); + assert.equal(isLegal('a', 'b'), undefined); }); it('should allow a legal move', () => { stacks = { @@ -156,8 +173,8 @@ if (typeof describe === 'function') { stacks = { a: [], b: [], c: [4, 3, 2, 1] }; assert.equal(checkForWin(), true); stacks = { a: [1], b: [], c: [4, 3, 2] }; - assert.equal(checkForWin(), false); - // I changed your victory condition to rod C + assert.equal(checkForWin(), undefined); + // I changed your victory condition to stack C }); }); From e4dc425f1c8674988e031c77246ac8ace82696d6 Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Sun, 28 Oct 2018 18:20:19 -0500 Subject: [PATCH 05/10] cleaned up some ES6 stuff --- 03week/towersOfHanoi.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 223d277b4..1942c6d89 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -13,18 +13,18 @@ let stacks = { c: [] }; -function printStacks() { +const printStacks = () => { console.log("a: " + stacks.a); console.log("b: " + stacks.b); console.log("c: " + stacks.c); } -function movePiece(startStack, endStack) { +const movePiece = (startStack, endStack) => { // console.log("When I move you move *just like that*") stacks[endStack].push(stacks[startStack].pop()); } -function isLegal(startStack, endStack) { +const isLegal = (startStack, endStack) => { const startLength = stacks[startStack].length; const endLength = stacks[endStack].length; const startLastElement = stacks[startStack][startLength - 1]; @@ -53,10 +53,8 @@ const validLetter = (letterInput) =>{ } } -function checkForWin() { - if(stacks["a"].length == 0 && stacks["b"].length == 0){ - return true; - } +const checkForWin = () => { + return stacks["a"].length == 0 && stacks["b"].length == 0; } const resetGame = () => { @@ -74,7 +72,7 @@ const resetGame = () => { // self challenge: add harder difficulty by adding a disk after reset // add turn counter and give user feed back on what a perfect game is compared to theirs -function towersOfHanoi(startStack, endStack) { +const towersOfHanoi = (startStack, endStack) => { const formatedStart = startStack.toLowerCase(); const formatedEnd = endStack.toLowerCase(); From 3ccab9718ffd02a18f801dcf272a2157e65e137d Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Mon, 29 Oct 2018 00:48:18 -0500 Subject: [PATCH 06/10] Comments to self about what I hate --- 03week/towersOfHanoi.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 1942c6d89..b95f5ef7d 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -22,6 +22,7 @@ const printStacks = () => { const movePiece = (startStack, endStack) => { // console.log("When I move you move *just like that*") stacks[endStack].push(stacks[startStack].pop()); + } const isLegal = (startStack, endStack) => { @@ -29,6 +30,11 @@ const isLegal = (startStack, endStack) => { const endLength = stacks[endStack].length; const startLastElement = stacks[startStack][startLength - 1]; const endLastElement = stacks[endStack][endLength - 1]; + // I don't like all this code, thinking about refactoring. Must be a more eligent way to do this + // likely use some kind of negative value on a slice?, dunno have to + // see how that would work. + + // console.log("Start Length " + startLength + " and last value " + startLastElement); // console.log("End Length " + endLength + " and last value " + endLastElement); if (startLength > 0) { @@ -51,16 +57,28 @@ const validLetter = (letterInput) =>{ default: return false; } + + // there are likely better ways to do this but I just wanted to use a switch statement! } const checkForWin = () => { return stacks["a"].length == 0 && stacks["b"].length == 0; + + // done this way so I could, in theory, expand the number of disks + // for whatever reason I always like making things that can expand! } const resetGame = () => { while(stacks['c'].length>0){ stacks['a'].push(stacks['c'].shift()); } + + // Not sure if this is prefered as opposed to just setting the object = to the values like + //stacks = { + // a: [4, 3, 2, 1], + // b: [], + // c: [] + // will experiment later. Also, ask if this causes memory leak if it does work } // let it begin! From 1bedb183aeb8c1edc20ddd472c5a9c6befb3f2f6 Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Mon, 29 Oct 2018 18:37:03 -0500 Subject: [PATCH 07/10] Some optmizations, fixed tests --- 03week/towersOfHanoi.js | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index b95f5ef7d..ed8c3b6e4 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -26,27 +26,13 @@ const movePiece = (startStack, endStack) => { } const isLegal = (startStack, endStack) => { - const startLength = stacks[startStack].length; - const endLength = stacks[endStack].length; - const startLastElement = stacks[startStack][startLength - 1]; - const endLastElement = stacks[endStack][endLength - 1]; - // I don't like all this code, thinking about refactoring. Must be a more eligent way to do this - // likely use some kind of negative value on a slice?, dunno have to - // see how that would work. - - - // console.log("Start Length " + startLength + " and last value " + startLastElement); - // console.log("End Length " + endLength + " and last value " + endLastElement); - if (startLength > 0) { - // we don't want to try and pop from an empty array so this is a stopgap measure - if(endLength == 0 || endLastElement>=startLastElement){ - // now we do the normal tower of hanoi size comparison - // if where we are going is empty, cool. If the bigger one is one bottom, cool - return true; - } - } + return stacks[startStack].length > 0 && (stacks[endStack].length == 0 || stacks[startStack].slice(-1)[0]{ switch(letterInput.toLowerCase()){ case "a": @@ -100,6 +86,7 @@ const towersOfHanoi = (startStack, endStack) => { if (formatedStart != formatedEnd){ movePiece(formatedStart, formatedEnd); if(checkForWin()){ + printStacks(); console.log("You win, you rock at computer science!") resetGame(); } @@ -189,7 +176,7 @@ if (typeof describe === 'function') { stacks = { a: [], b: [], c: [4, 3, 2, 1] }; assert.equal(checkForWin(), true); stacks = { a: [1], b: [], c: [4, 3, 2] }; - assert.equal(checkForWin(), undefined); + assert.equal(checkForWin(), false); // I changed your victory condition to stack C }); }); From 892db341e0db6601245c8596ca56f0fc931c600c Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Mon, 29 Oct 2018 19:04:40 -0500 Subject: [PATCH 08/10] Final set of corrections and comments for the night, think we are done --- 03week/towersOfHanoi.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index ed8c3b6e4..818a30ba2 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -28,10 +28,11 @@ const movePiece = (startStack, endStack) => { const isLegal = (startStack, endStack) => { return stacks[startStack].length > 0 && (stacks[endStack].length == 0 || stacks[startStack].slice(-1)[0]{ switch(letterInput.toLowerCase()){ @@ -44,7 +45,7 @@ const validLetter = (letterInput) =>{ return false; } - // there are likely better ways to do this but I just wanted to use a switch statement! + // there are likely better ways to do this but I just wanted to use a switch statement, cause I never do! } const checkForWin = () => { @@ -52,6 +53,8 @@ const checkForWin = () => { // done this way so I could, in theory, expand the number of disks // for whatever reason I always like making things that can expand! + // reather than checking for some absoulte size that might change + // just make sure that nothing remains on the other tiles and trust our move logic is good! } const resetGame = () => { @@ -64,10 +67,11 @@ const resetGame = () => { // a: [4, 3, 2, 1], // b: [], // c: [] - // will experiment later. Also, ask if this causes memory leak if it does work + // will experiment later. Also, need to ask if this causes memory leak if it does work + // this old c programer so afarid of memory misallocation! } - // let it begin! + // let it begin! Code Plan! // We get user input from where they want to take from to where they want to put to (startStack, endStack) // We see if this is a legal move isLegal()T/F // if so we move the peiece movePiece() @@ -79,7 +83,8 @@ const resetGame = () => { const towersOfHanoi = (startStack, endStack) => { const formatedStart = startStack.toLowerCase(); const formatedEnd = endStack.toLowerCase(); - + // since I used these so much, I decided to make variable for them, could remove if it is a good + // practice to not make temps for something like this if(validLetter(formatedStart) && validLetter(formatedEnd)){ if(isLegal(formatedStart, formatedEnd)){ @@ -97,14 +102,14 @@ const towersOfHanoi = (startStack, endStack) => { console.log("Not valid move, can't move bigger numbers on top of smaller numbers and can't move empty rows at all!") } }else{ - console.log("Invalid letter") + console.log("Invalid letter: Please only a, b or c") } } -function getPrompt() { +const getPrompt = () => { printStacks(); rl.question('start stack: ', (startStack) => { rl.question('end stack: ', (endStack) => { @@ -119,11 +124,13 @@ function getPrompt() { if (typeof describe === 'function') { // new -// note: For my functions I wasn't returning false values, only undefines. For whatever reason + +// note: For some of my function's weren't returning false values, but rather undefines. For whatever reason // mocha will fail the test when it tests for false and sees undefined. -// i modified the tests to undefined, though this feels like a poor solution. +// I modified the tests to undefined when it mattered, though this feels like a poor solution. // will update them with your recomendations if you have any. - describe('#validLetter()', () => { + +describe('#validLetter()', () => { it('Should disallow invalid inputs', () => { assert.equal(validLetter('dog'), false); }); @@ -160,7 +167,7 @@ if (typeof describe === 'function') { b: [1], c: [] }; - assert.equal(isLegal('a', 'b'), undefined); + assert.equal(isLegal('a', 'b'), false); }); it('should allow a legal move', () => { stacks = { From b0d5b4e87b7495478c3739a97a976b5dbb27e2bb Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Tue, 30 Oct 2018 01:25:11 -0500 Subject: [PATCH 09/10] Cleaned up spaces and comments a bit --- 03week/towersOfHanoi.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 818a30ba2..53b32d278 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -20,41 +20,33 @@ const printStacks = () => { } const movePiece = (startStack, endStack) => { - // console.log("When I move you move *just like that*") stacks[endStack].push(stacks[startStack].pop()); - } const isLegal = (startStack, endStack) => { - return stacks[startStack].length > 0 && (stacks[endStack].length == 0 || stacks[startStack].slice(-1)[0] 0 && stacks[endStack].length == 0 || stacks[startStack].slice(-1)[0]{ switch(letterInput.toLowerCase()){ case "a": case "b": case "c": - // console.log("valid letter"); return true; default: return false; } - // there are likely better ways to do this but I just wanted to use a switch statement, cause I never do! } const checkForWin = () => { return stacks["a"].length == 0 && stacks["b"].length == 0; - // done this way so I could, in theory, expand the number of disks // for whatever reason I always like making things that can expand! - // reather than checking for some absoulte size that might change - // just make sure that nothing remains on the other tiles and trust our move logic is good! } const resetGame = () => { @@ -83,8 +75,8 @@ const resetGame = () => { const towersOfHanoi = (startStack, endStack) => { const formatedStart = startStack.toLowerCase(); const formatedEnd = endStack.toLowerCase(); - // since I used these so much, I decided to make variable for them, could remove if it is a good - // practice to not make temps for something like this + // since I used these so much, I decided to make variable for them + // could remove if it is a good practice to not make temps for something like this if(validLetter(formatedStart) && validLetter(formatedEnd)){ if(isLegal(formatedStart, formatedEnd)){ @@ -103,12 +95,9 @@ const towersOfHanoi = (startStack, endStack) => { } }else{ console.log("Invalid letter: Please only a, b or c") - } } - - const getPrompt = () => { printStacks(); rl.question('start stack: ', (startStack) => { @@ -152,8 +141,8 @@ describe('#validLetter()', () => { }); }); - //new + describe('#towersOfHanoi()', () => { it('should be able to move a block', () => { towersOfHanoi('a', 'b'); From 031a3b48aa258cb6ed281ecc384e7bb80ff17153 Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Tue, 30 Oct 2018 16:54:46 -0500 Subject: [PATCH 10/10] readability of a long return statement --- 03week/towersOfHanoi.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 53b32d278..dcf8d63ed 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -24,7 +24,9 @@ const movePiece = (startStack, endStack) => { } const isLegal = (startStack, endStack) => { - return stacks[startStack].length > 0 && stacks[endStack].length == 0 || stacks[startStack].slice(-1)[0] 0 && + stacks[endStack].length == 0 || + stacks[startStack].slice(-1)[0]