diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 40b9ebe92..0275921c4 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -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()); +} +// 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) { + return true; + } else if (stacks[startStack].pop() < stacks[endStack].pop()) { + 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)) { + isLegal(startStack, endStack) + } + checkForWin(); } + function getPrompt() { printStacks(); rl.question('start stack: ', (startStack) => { @@ -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 diff --git a/04week/mastermind.js b/04week/mastermind.js deleted file mode 100644 index 60e5cfa18..000000000 --- a/04week/mastermind.js +++ /dev/null @@ -1,77 +0,0 @@ -'use strict'; - -const assert = require('assert'); -const readline = require('readline'); -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout -}); - -let board = []; -let solution = ''; -let letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; - -function printBoard() { - for (let i = 0; i < board.length; i++) { - console.log(board[i]); - } -} - -function generateSolution() { - for (let i = 0; i < 4; i++) { - const randomIndex = getRandomInt(0, letters.length); - solution += letters[randomIndex]; - } -} - -function getRandomInt(min, max) { - return Math.floor(Math.random() * (max - min)) + min; -} - -function generateHint() { - // your code here -} - -function mastermind(guess) { - solution = 'abcd'; // Comment this out to generate a random solution - // your code here -} - - -function getPrompt() { - rl.question('guess: ', (guess) => { - mastermind(guess); - printBoard(); - getPrompt(); - }); -} - -// Tests - -if (typeof describe === 'function') { - solution = 'abcd'; - describe('#mastermind()', () => { - it('should register a guess and generate hints', () => { - mastermind('aabb'); - assert.equal(board.length, 1); - }); - it('should be able to detect a win', () => { - assert.equal(mastermind(solution), 'You guessed it!'); - }); - }); - - describe('#generateHint()', () => { - it('should generate hints', () => { - assert.equal(generateHint('abdc'), '2-2'); - }); - it('should generate hints if solution has duplicates', () => { - assert.equal(generateHint('aabb'), '1-1'); - }); - - }); - -} else { - - generateSolution(); - getPrompt(); -} diff --git a/05week/spaceTravelToMars.js b/05week/spaceTravelToMars.js index ce258a382..f2a7f9a96 100644 --- a/05week/spaceTravelToMars.js +++ b/05week/spaceTravelToMars.js @@ -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'){ @@ -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'); @@ -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(){ @@ -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'); @@ -55,5 +82,7 @@ if (typeof describe === 'function'){ crewMember2.enterShip(hermes); assert.equal(hermes.missionStatement(), "Interplanetary Space Travel"); }); + // designated all the vars + // }); } diff --git a/package-lock.json b/package-lock.json index 62353c45d..f28cfa5c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,16 +4,6 @@ "lockfileVersion": 1, "requires": true, "dependencies": { - "JSONStream": { - "version": "0.8.4", - "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-0.8.4.tgz", - "integrity": "sha1-kWV9/m/4V0gwZhMrRhi2Lo9Ih70=", - "dev": true, - "requires": { - "jsonparse": "0.0.5", - "through": "2.3.8" - } - }, "abab": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/abab/-/abab-1.0.4.tgz", @@ -2707,6 +2697,16 @@ "integrity": "sha1-T9kss04OnbPInIYi7PUfm5eMbLk=", "dev": true }, + "JSONStream": { + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-0.8.4.tgz", + "integrity": "sha1-kWV9/m/4V0gwZhMrRhi2Lo9Ih70=", + "dev": true, + "requires": { + "jsonparse": "0.0.5", + "through": "2.3.8" + } + }, "jsprim": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", @@ -4367,6 +4367,11 @@ "through": "2.3.8" } }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" + }, "string-to-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/string-to-stream/-/string-to-stream-1.1.0.tgz", @@ -4427,11 +4432,6 @@ } } }, - "string_decoder": { - "version": "0.10.31", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" - }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz",