From 4d49b6a9efdd5ac3b2263125624a6d52d000f874 Mon Sep 17 00:00:00 2001 From: Kiley Lewis Date: Tue, 23 Apr 2019 18:13:03 -0500 Subject: [PATCH 1/3] mastermind progress --- 04week/mastermind.js | 41 +++++++++++++++++++++++++++++++++++++---- package-lock.json | 26 ++++++++++++++++---------- package.json | 1 + 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/04week/mastermind.js b/04week/mastermind.js index 60e5cfa18..12dc31909 100644 --- a/04week/mastermind.js +++ b/04week/mastermind.js @@ -28,13 +28,46 @@ function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min)) + min; } -function generateHint() { - // your code here +function generateHint(solution, guess) { + + let solutionArray = solution.split(''); + + let guessArray = guess.split(''); + + let correctLetterLocations = 0; + + for (let i = 0; i < solutionArray.length; i++) { + if (solutionArray[i] == guessArray[i]) { + correctLetterLocations = correctLetterLocations +1; + solutionArray[i] = null; + } + } + + let correctLetters = 0; + + for (let i = 0; i < solutionArray.length; i++) { + if (guessArray.indexOf([i]) == solutionArray[i]) { + let targetIndex = guessArray; + if (targetIndex > -1) { + correctLetters = correctLetters +1; + solutionArray[i] = null; + } + } + } + + let colors = require('colors'); + + return 'correctLetterLocations.red - correctLetters.white'; + + } function mastermind(guess) { - solution = 'abcd'; // Comment this out to generate a random solution - // your code here + const solution = 'abcd'; // Comment this out to generate a random solution + + if (guess === solution) { + return 'you guessed it!'; + } } diff --git a/package-lock.json b/package-lock.json index bd07c0e56..71548816c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -553,9 +553,9 @@ } }, "colors": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/colors/-/colors-0.6.2.tgz", - "integrity": "sha1-JCP+ZnisDF2uiFLl0OW+CMmXq8w=" + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.3.3.tgz", + "integrity": "sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg==" }, "colors-tmpl": { "version": "0.1.1", @@ -563,6 +563,13 @@ "integrity": "sha1-F+n5rYBceS/6OsagSctzJ9llt/4=", "requires": { "colors": "~0.6.2" + }, + "dependencies": { + "colors": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/colors/-/colors-0.6.2.tgz", + "integrity": "sha1-JCP+ZnisDF2uiFLl0OW+CMmXq8w=" + } } }, "combined-stream": { @@ -1728,15 +1735,14 @@ "version": "github:kevincolten/htmllint-cli#5901ac1f6cd612f484f40c7f4f7515f22a2ba52d", "from": "github:kevincolten/htmllint-cli", "requires": { - "bluebird": "^3.4.7", - "chalk": "^1.1.3", + "bluebird": "^3.5.1", + "chalk": "^2.3.0", "cjson": "^0.5.0", "glob": "^7.1.1", - "htmllint": "^0.6.0", - "liftoff": "^2.3.0", - "promise": "^7.1.1", - "semver": "^5.3.0", - "yargs": "^6.6.0" + "htmllint": "^0.7.0", + "liftoff": "^2.5.0", + "semver": "^5.4.1", + "yargs": "^10.0.3" }, "dependencies": { "ansi-styles": { diff --git a/package.json b/package.json index aff08712c..57080b13d 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ }, "homepage": "https://github.com/AustinCodingAcademy/javascript-workbook#readme", "dependencies": { + "colors": "^1.3.3", "eslint": "^3.19.0", "functional-javascript-workshop": "^1.0.6", "htmllint-cli": "github:kevincolten/htmllint-cli", From a65cb23892c0bcc41df2d0b6aa4283f7dc8f1681 Mon Sep 17 00:00:00 2001 From: Kiley Lewis Date: Wed, 24 Apr 2019 17:17:19 -0500 Subject: [PATCH 2/3] mastermind update --- 04week/mastermind.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/04week/mastermind.js b/04week/mastermind.js index 12dc31909..fe8c85826 100644 --- a/04week/mastermind.js +++ b/04week/mastermind.js @@ -48,10 +48,10 @@ function generateHint(solution, guess) { for (let i = 0; i < solutionArray.length; i++) { if (guessArray.indexOf([i]) == solutionArray[i]) { let targetIndex = guessArray; - if (targetIndex > -1) { - correctLetters = correctLetters +1; - solutionArray[i] = null; - } + } + if (targetIndex > -1) { + correctLetters = correctLetters +1; + solutionArray[i] = null; } } From 3c4897f1956a31b2a4d29502d534de53c3c969c9 Mon Sep 17 00:00:00 2001 From: Kiley Lewis Date: Sun, 28 Apr 2019 21:36:01 -0500 Subject: [PATCH 3/3] mm update --- 04week/mastermind.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/04week/mastermind.js b/04week/mastermind.js index fe8c85826..6d427b4a4 100644 --- a/04week/mastermind.js +++ b/04week/mastermind.js @@ -8,8 +8,9 @@ const rl = readline.createInterface({ }); let board = []; -let solution = ''; -let letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; +let solution = 'abcd'; +let letters = ['a', 'b', 'c', 'd']; +let colors = require('colors'); function printBoard() { for (let i = 0; i < board.length; i++) { @@ -35,36 +36,31 @@ function generateHint(solution, guess) { let guessArray = guess.split(''); let correctLetterLocations = 0; + let correctLetters = 0; for (let i = 0; i < solutionArray.length; i++) { - if (solutionArray[i] == guessArray[i]) { + if (solutionArray[i] === guessArray[i]) { correctLetterLocations = correctLetterLocations +1; solutionArray[i] = null; } } - let correctLetters = 0; - for (let i = 0; i < solutionArray.length; i++) { - if (guessArray.indexOf([i]) == solutionArray[i]) { - let targetIndex = guessArray; - } - if (targetIndex > -1) { - correctLetters = correctLetters +1; - solutionArray[i] = null; + if (guessArray.indexOf([i]) === solutionArray[i]) { + let targetIndex = guessArray.indexOf([i]); + if (targetIndex > -1) { + correctLetters = correctLetters +1; + solutionArray[i] = null; + } } } - let colors = require('colors'); - - return 'correctLetterLocations.red - correctLetters.white'; + return correctLetterLocations.red + correctLetters.white; - } + function mastermind(guess) { - const solution = 'abcd'; // Comment this out to generate a random solution - if (guess === solution) { return 'you guessed it!'; }