From d38165dd8914bbcdafcc3269be63290a65b455c0 Mon Sep 17 00:00:00 2001 From: cfissell50 Date: Tue, 24 Oct 2017 20:06:20 -0500 Subject: [PATCH 1/8] comments for test --- 03week/towersOfHanoi.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 40b9ebe92..07a25ce61 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -52,3 +52,5 @@ function getPrompt() { getPrompt(); +// Test for legal move where [this] < [existing block] +// Print 'YOU WIN' when key c = 4,3,2,1 From ec7127bb859c6117a3064411388d61eb9efec2cb Mon Sep 17 00:00:00 2001 From: cfissell50 Date: Thu, 26 Oct 2017 14:07:23 -0500 Subject: [PATCH 2/8] update --- 03week/towersOfHanoi.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 07a25ce61..b9daff6e6 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -52,5 +52,6 @@ function getPrompt() { getPrompt(); -// Test for legal move where [this] < [existing block] -// Print 'YOU WIN' when key c = 4,3,2,1 +// Test for legal move where [this] < [existing block] where a larger number cant follow a smaller number +// Win function recognizing key c = 4,3,2,1 +// From 32a0a009b92bce95d97c180514a8ce5e75047241 Mon Sep 17 00:00:00 2001 From: cfissell50 Date: Thu, 26 Oct 2017 14:10:12 -0500 Subject: [PATCH 3/8] wat commit --- 03week/towersOfHanoi.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index b9daff6e6..07a25ce61 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -52,6 +52,5 @@ function getPrompt() { getPrompt(); -// Test for legal move where [this] < [existing block] where a larger number cant follow a smaller number -// Win function recognizing key c = 4,3,2,1 -// +// Test for legal move where [this] < [existing block] +// Print 'YOU WIN' when key c = 4,3,2,1 From 5ff550a0e1029cc680ee2d68e412a0a78d1bee9a Mon Sep 17 00:00:00 2001 From: cfissell50 Date: Mon, 30 Oct 2017 18:31:09 -0500 Subject: [PATCH 4/8] polishing details --- 03week/towersOfHanoi.js | 42 +++++++++++++++------- 04week/mastermind.js | 77 ----------------------------------------- 2 files changed, 30 insertions(+), 89 deletions(-) delete mode 100644 04week/mastermind.js diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 07a25ce61..4e5cb5d11 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -19,26 +19,41 @@ function printStacks() { console.log("c: " + stacks.c); } -function movePiece() { - // Your code here - +const movePiece = (startStack, endStack) => { + stacks[endStack].push(stacks[startStack].pop()); } -function isLegal() { - // Your code here +const isLegal = (startStack, endStack) => { + // Your code here + 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 +const checkForWin = () => { + // Your code here + if (stacks.c.length === 4) { + return true; + } else { + return false; + } } -function towersOfHanoi(startStack, endStack) { - // Your code here +const towersOfHanoi = (startStack, endStack) => { + if (movePiece(startStack, endStack)) { + isLegal(startStack, endStack) + } + checkForWin(); } + function getPrompt() { printStacks(); rl.question('start stack: ', (startStack) => { @@ -51,6 +66,9 @@ function getPrompt() { getPrompt(); - -// Test for legal move where [this] < [existing block] -// Print 'YOU WIN' when key c = 4,3,2,1 +// 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(); -} From 6104136ecce87e50473a88d9bcf45f4ebcc72fae Mon Sep 17 00:00:00 2001 From: cfissell50 Date: Tue, 31 Oct 2017 12:41:53 -0500 Subject: [PATCH 5/8] towers almost fini --- 03week/towersOfHanoi.js | 21 ++++++++--- 04week/mastermind.js | 77 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 04week/mastermind.js diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 4e5cb5d11..e115c0494 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -19,13 +19,24 @@ function printStacks() { console.log("c: " + stacks.c); } +// 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 + +// 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) => { - // Your code here if (stacks[endStack].length === 0) { return true; } else if (stacks[startStack].pop() < stacks[endStack].pop()) { @@ -36,16 +47,16 @@ const isLegal = (startStack, endStack) => { } +// 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 = () => { - // Your code here if (stacks.c.length === 4) { - return true; + console.log('Winner, Winner, Chicken Dinner!!'); } else { return false; } } - const towersOfHanoi = (startStack, endStack) => { if (movePiece(startStack, endStack)) { isLegal(startStack, endStack) diff --git a/04week/mastermind.js b/04week/mastermind.js new file mode 100644 index 000000000..60e5cfa18 --- /dev/null +++ b/04week/mastermind.js @@ -0,0 +1,77 @@ +'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(); +} From b2c2b78ca1187eb7663694f25496423392cb26ed Mon Sep 17 00:00:00 2001 From: cfissell50 Date: Tue, 31 Oct 2017 13:31:48 -0500 Subject: [PATCH 6/8] everything but tests --- 03week/towersOfHanoi.js | 2 ++ 04week/mastermind.js | 77 ----------------------------------------- package-lock.json | 30 ++++++++-------- 3 files changed, 17 insertions(+), 92 deletions(-) delete mode 100644 04week/mastermind.js diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index e115c0494..35805f24a 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -57,6 +57,8 @@ const checkForWin = () => { } } +// 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) 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/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", From 0b6fef47414733628b7b55283b2d760ffab13724 Mon Sep 17 00:00:00 2001 From: cfissell50 Date: Wed, 1 Nov 2017 18:10:39 -0500 Subject: [PATCH 7/8] space travels yo --- 05week/spaceTravelToMars.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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 + // }); } From 0ac08947111ba76d92796d6cc46a1fa3d5b3d41a Mon Sep 17 00:00:00 2001 From: cfissell50 Date: Wed, 1 Nov 2017 18:22:16 -0500 Subject: [PATCH 8/8] test finally --- 03week/towersOfHanoi.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 35805f24a..0275921c4 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -79,6 +79,26 @@ 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