Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 63 additions & 10 deletions 03week/towersOfHanoi.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,54 @@ function printStacks() {
console.log("c: " + stacks.c);
}

function movePiece() {
// Your code here
// RUBRIC
// Move piece from stack to stack 17
// Working is legal function 17
// Working check for win function 17
// Working reset function 17
// Clean PR , es6 syntax/linting 8
// Function plan in comments (each function has a stated purpose and method) 16
// At least 2 tests 8

}
// es6 notation fat arrow everything//const everything

function isLegal() {
// 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());
Copy link

Choose a reason for hiding this comment

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

Very concise!

}

// 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) {
Copy link

Choose a reason for hiding this comment

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

What happens if the startStack is empty?

return true;
} else if (stacks[startStack].pop() < stacks[endStack].pop()) {
Copy link

Choose a reason for hiding this comment

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

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

return true;
} else {
return false;
}
}

function checkForWin() {
// Your code here

// checkforwin should use dot method in if statement, legal function should protect argument from c having out of order values.
// length of c === 4 should result in win
const checkForWin = () => {
if (stacks.c.length === 4) {
console.log('Winner, Winner, Chicken Dinner!!');
} else {
return false;
}
}

function towersOfHanoi(startStack, endStack) {
// Your code here

// 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)) {
Copy link

Choose a reason for hiding this comment

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

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.

isLegal(startStack, endStack)
}
checkForWin();
}


function getPrompt() {
printStacks();
rl.question('start stack: ', (startStack) => {
Expand All @@ -52,3 +80,28 @@ function getPrompt() {
getPrompt();


// Moving stack should be from (a,c) should end a: 4,3,2 | b: | c: 1
describe('#towersOfHanoi()', () => {
it('should be able to move a block', () => {
towersOfHanoi('a', 'c');
assert.deepEqual(stacks, { a: [4, 3, 2], b: [], c: [1] });
});
});

describe('#checkForWin()', () => {
it('should recognize a win', () => {
let stacks = {
a: [],
b: [],
c: [4,3,2,1]
};
assert.equal(checkForWin(), true);
});
});

// Test for legal move where [startStack] < [endStack] where a larger number cant follow a smaller number
// Win function recognizing key c = 4,3,2,1 printing 'YOU WIN!'
// guard against random letters and redundancies
// checking against different data type
// Moving stack should be from (a,c) should end a: 4,3,2 | b: | c: 1
// top disc
77 changes: 0 additions & 77 deletions 04week/mastermind.js

This file was deleted.

31 changes: 30 additions & 1 deletion 05week/spaceTravelToMars.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,28 @@ let jobTypes = {
programmer: 'Any Ship!'
};

// Your code here
// 2 classes , CrewMember and Ship,
// function entership should add crewmember to ship
// function missionstatement should print "Can't perform a mission yet."

class CrewMember {
constructor(name, job, specialSkill){
this.name = name;
this.job = job;
this.specialSkill = specialSkill;
this.ship = [];
}
}

class Ship {
constructor(name, type, ability){
this.name = name;
this.type = type;
this.ability = ability;
this.crew = [];
}
}


//tests
if (typeof describe === 'function'){
Expand All @@ -21,6 +42,8 @@ if (typeof describe === 'function'){
assert.equal(crewMember1.specialSkill, 'chemistry');
assert.equal(crewMember1.ship, null);
});
// crewmember should have a name, job, specialskill, and a ship
// these dot methods should print out these properties

it('can enter a ship', function(){
let mav = new Ship('Mars Ascent Vehicle', 'MAV', 'Ascend into low orbit');
Expand All @@ -31,6 +54,8 @@ if (typeof describe === 'function'){
assert.equal(mav.crew[0], crewMember1);
});
});
// should be a ship class with type name and what its going to do
// after crewmember is added to ship it should correspond with the correct returns

describe('Ship', function(){
it('should have a name, a type, an ability and an empty crew upon instantiation', function(){
Expand All @@ -40,6 +65,8 @@ if (typeof describe === 'function'){
assert.equal(mav.ability, 'Ascend into low orbit');
assert.equal(mav.crew.length, 0);
});
// ship class should have name type and an ability and an empty crew
// so when mav is referenced it should print out those returns

it('can return a mission statement correctly', function(){
let mav = new Ship('Mars Ascent Vehicle', 'MAV', 'Ascend into low orbit');
Expand All @@ -55,5 +82,7 @@ if (typeof describe === 'function'){
crewMember2.enterShip(hermes);
assert.equal(hermes.missionStatement(), "Interplanetary Space Travel");
});
// designated all the vars
//
});
}
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.