From a11633df61bb6d527a6a59a30ae5aee45c368197 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 10 Jul 2017 12:41:03 -0400 Subject: [PATCH 001/523] basic compare for longest string, no edge or corner cases --- longestString/longestString.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/longestString/longestString.js b/longestString/longestString.js index e36a1c1..198387f 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -1,4 +1,24 @@ /* * Write a function that accepts an array of strings. * Return the longest string in the array. - */ \ No newline at end of file + */ + +/* Take the first array item and put it in a "holding" array. + * Compare it to the next anArray, put the bigger of the two in the holding array. + */ + +testanArray = ['fred', 'ted', 'bob', 'alice', 'joe', 'arnold', 'mary', 'jebedaiah', 'ed', 'zachahurres', 'mae', 'antidisestablishmentarianism'] + +const bigString = function (anArr) { + const holdBig = [anArr[0]]; + for (let i = 0; i < anArr.length; i++) { + if (holdBig[0].length < anArr[i].length) { + holdBig.pop(); + // console.log(anArr[i]); + holdBig.push(anArr[i]); + }; + }; + return holdBig[0]; +}; + +console.log(bigString(testanArray)); From df8ff64486cf9074f8fc5c86a8aade69baa58746 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 10 Jul 2017 12:44:45 -0400 Subject: [PATCH 002/523] =?UTF-8?q?basic=20comparison=20=E2=88=9A=20no=20e?= =?UTF-8?q?dge=20or=20corner=20cases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- longestString/longestString.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/longestString/longestString.js b/longestString/longestString.js index 198387f..47acd38 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -7,7 +7,7 @@ * Compare it to the next anArray, put the bigger of the two in the holding array. */ -testanArray = ['fred', 'ted', 'bob', 'alice', 'joe', 'arnold', 'mary', 'jebedaiah', 'ed', 'zachahurres', 'mae', 'antidisestablishmentarianism'] +// testanArray = ['fred', 'ted', 'bob', 'alice', 'joe', 'arnold', 'mary', 'jebedaiah', 'ed', 'zachahurres', 'mae', 'antidisestablishmentarianism'] const bigString = function (anArr) { const holdBig = [anArr[0]]; @@ -21,4 +21,4 @@ const bigString = function (anArr) { return holdBig[0]; }; -console.log(bigString(testanArray)); +// console.log(bigString(testanArray)); From e3c6c05da42e11bc458e7e08cc1ea606dced6c09 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 10 Jul 2017 14:44:36 -0400 Subject: [PATCH 003/523] to be refactored for edge cases --- longestString/longestString.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/longestString/longestString.js b/longestString/longestString.js index 47acd38..904e8d6 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -22,3 +22,6 @@ const bigString = function (anArr) { }; // console.log(bigString(testanArray)); + +// Refactor to return an array of strings if there's a tie? +// Refactor to handle non-Array arguments? From 4a05a5d62f04fa55bd79766ec3986d83921898a3 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 10 Jul 2017 17:26:14 -0400 Subject: [PATCH 004/523] refactoring notes --- longestString/longestString.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longestString/longestString.js b/longestString/longestString.js index 904e8d6..111eb37 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -23,5 +23,5 @@ const bigString = function (anArr) { // console.log(bigString(testanArray)); -// Refactor to return an array of strings if there's a tie? +// Refactor to return an array of the equal length strings if there's a tie? // Refactor to handle non-Array arguments? From 19fa6b0faa388abb176443a7a1e839d4476e22be Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 11 Jul 2017 11:55:15 -0400 Subject: [PATCH 005/523] attempt at handling tie: FAIL --- longestString/longestString.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/longestString/longestString.js b/longestString/longestString.js index 111eb37..4e2ee1b 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -6,22 +6,30 @@ /* Take the first array item and put it in a "holding" array. * Compare it to the next anArray, put the bigger of the two in the holding array. */ - -// testanArray = ['fred', 'ted', 'bob', 'alice', 'joe', 'arnold', 'mary', 'jebedaiah', 'ed', 'zachahurres', 'mae', 'antidisestablishmentarianism'] - const bigString = function (anArr) { const holdBig = [anArr[0]]; - for (let i = 0; i < anArr.length; i++) { + const tie = ['There\'s a tie: ']; + + for (let i = 1; i < anArr.length; i++) { if (holdBig[0].length < anArr[i].length) { holdBig.pop(); // console.log(anArr[i]); holdBig.push(anArr[i]); }; + // tie if length match but different string - NOPE + // if (holdBig[0].length === anArr[i].length) { + // tie.push(anArr[i]); + // return `${tie[0]} ${tie[1]}`; + // } }; return holdBig[0]; }; -// console.log(bigString(testanArray)); +testAnArray = ['fred', 'ted', 'bob', 'alice', 'joe', 'arnold', 'mary', 'jebedaiah', 'ed', 'zachahurres', 'mae', 'antidisestablishmentarianism'] +console.log(bigString(testAnArray)); + +// Refactor to return an array of the equal length strings if there's a tie? √ +// testAnArrayTie = ['fred', 'ted', 'bob', 'antidisestablishmentarianism', 'alice', 'joe', 'arnold', 'mary', 'jebedaiah', 'ed', 'zachahurres', 'mae', 'antidisestablishmentarianism', 'manny'] +// console.log(bigString(testAnArrayTie)); -// Refactor to return an array of the equal length strings if there's a tie? // Refactor to handle non-Array arguments? From d17b2fcad1899945804d1661c5e7f80192e6a245 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 11 Jul 2017 12:32:41 -0400 Subject: [PATCH 006/523] done, no add'l data structure --- isUnique/isUnique.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 isUnique/isUnique.js diff --git a/isUnique/isUnique.js b/isUnique/isUnique.js new file mode 100755 index 0000000..18dd90a --- /dev/null +++ b/isUnique/isUnique.js @@ -0,0 +1,13 @@ +/* +* Implement an algorithm to determine if a string has all unique characters. +* Extra Credit - Answer this question - What if you cannot use additional data structures? +*/ + +const isUnique = (str) => { + for (let i = 1; i < str.length; i++) { + if (str[0] === str[i]) return false; + } return true; +}; + +console.log(isUnique('abcdhijklmnopqrstuv')); // true +console.log(isUnique('abcdefga')); // false From 3057f9d9f96684f97d00eb3a0592dc28414622f3 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 11 Jul 2017 16:16:09 -0400 Subject: [PATCH 007/523] basic solution, no edge/corner case handling --- longestString/longestString.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longestString/longestString.js b/longestString/longestString.js index 4e2ee1b..44a95be 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -26,7 +26,7 @@ const bigString = function (anArr) { }; testAnArray = ['fred', 'ted', 'bob', 'alice', 'joe', 'arnold', 'mary', 'jebedaiah', 'ed', 'zachahurres', 'mae', 'antidisestablishmentarianism'] -console.log(bigString(testAnArray)); +console.log(bigString(testAnArray)); // ---> antidisestablishmentarianism // Refactor to return an array of the equal length strings if there's a tie? √ // testAnArrayTie = ['fred', 'ted', 'bob', 'antidisestablishmentarianism', 'alice', 'joe', 'arnold', 'mary', 'jebedaiah', 'ed', 'zachahurres', 'mae', 'antidisestablishmentarianism', 'manny'] From 4d5cb152eb8c7a52560d033f00d551babbff7256 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 11 Jul 2017 18:38:54 -0400 Subject: [PATCH 008/523] Merge branch 'master' of https://github.com/ryanhca/CS1-Code-Challenges --- longestString/solution.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/longestString/solution.js b/longestString/solution.js index 8cc3d33..13a0e9a 100644 --- a/longestString/solution.js +++ b/longestString/solution.js @@ -1,4 +1,5 @@ const longestString = (strArr) => { +<<<<<<< HEAD // tempStr variable to hold the string let tempStr = ''; // loop over strArr @@ -21,3 +22,13 @@ const longStr = (arr) => { } console.log(`Jesh: ${longStr(['abc', 'def', 'gasdfasf', 'asdf', 'e', 'agwoaiengpoing', 'pp'])}`); +======= + let tempStr = ''; + strArr.forEach(str => { + if(str.length > tempStr.length) tempStr = str; + }); + return tempStr; +}; + +longestString(['abc', 'def', 'gasdfasf', 'asdf', 'e', 'agwoaiengpoing']); +>>>>>>> 9ec7f38c8f1bfc9727e15ce95c4c55f50815bfba From 0f786d7b4b0a52a48168391d3d605e44d26b866b Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 11 Jul 2017 18:39:22 -0400 Subject: [PATCH 009/523] Changes --- readme.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 2fb1c7d..0d7f291 100644 --- a/readme.md +++ b/readme.md @@ -1 +1,63 @@ -# CS1 - Lambda School Code Challenges \ No newline at end of file +# CS1 - Lambda School Code Challenges + +## steps to ensuring your changes get pulled down +1. You will only need to run this step once +```console +git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git +``` + +NOTE: VVVVVVVV I think this is incorrect VVVVVVVVV +2. To get the changes to the repo each day run this +```console +git pull upstream master +``` + +3. You'll then have to resolve any merge conflicts that come up. Don't worry, you'll be pros at this after you're done and this is something that you'll have to do in the real world... all the time. :/ + +*** + +# NOTE TO RYAN from Patrick: + +1. After the origin and upstream are established, such that: +```console +$ git remote -v +origin https://github.com/ryanhca/CS1-Code-Challenges.git (fetch) +origin https://github.com/ryanhca/CS1-Code-Challenges.git (push) +upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges (fetch) +upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges (push) +``` + +2. Then, to get the changes from the origin (ryanhca) master, the srudents will need to run: +```console +$ git pull origin master +``` + +3. These commands posted durig the Brown Bag + ```console + git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git + git pull upstream master + git remote -v + + git remote set-url upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges + // git push/commit etc. + ``` + +4. ...should be changed to: + ```console + $ git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git + $ git pull upstream master + $ git remote -v + + $ git remote set-url upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges + + // TO GET NEW CONTENT: + $ git pull origin master + // May require merge conflict resolution + + // STAGING FILES (git add) & MAKING LOCAL COMMITTS (git commit -m 'awesome message') STAYS THE SAME. + + // TO PUSH YOUR WORK TO YOUR GITHUB REPOSITORY: + git push upstream master + + // TO SUBMIT A PULL REQUEST TO RYAN'S (origin) GITHUB REPOSITORY, GO ONLINE TO https://github.com/ryanhca/CS1-Code-Challenges RYAN'S REPOSITORY AND SUBMIT A NEW PULL REQUEST + ``` From 40b6f554c65a0864ffcd137a1addf4cfe2861d91 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 11 Jul 2017 18:42:05 -0400 Subject: [PATCH 010/523] hmmm --- longestString/solution.js | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/longestString/solution.js b/longestString/solution.js index f066c72..8cc3d33 100644 --- a/longestString/solution.js +++ b/longestString/solution.js @@ -1,6 +1,4 @@ const longestString = (strArr) => { -<<<<<<< HEAD -<<<<<<< HEAD // tempStr variable to hold the string let tempStr = ''; // loop over strArr @@ -23,23 +21,3 @@ const longStr = (arr) => { } console.log(`Jesh: ${longStr(['abc', 'def', 'gasdfasf', 'asdf', 'e', 'agwoaiengpoing', 'pp'])}`); -======= - let tempStr = ''; - strArr.forEach(str => { - if(str.length > tempStr.length) tempStr = str; - }); - return tempStr; -}; - -longestString(['abc', 'def', 'gasdfasf', 'asdf', 'e', 'agwoaiengpoing']); ->>>>>>> 9ec7f38c8f1bfc9727e15ce95c4c55f50815bfba -======= - let tempStr = ''; - strArr.forEach(str => { - if(str.length > tempStr.length) tempStr = str; - }); - return tempStr; -}; - -longestString(['abc', 'def', 'gasdfasf', 'asdf', 'e', 'agwoaiengpoing']); ->>>>>>> 9ec7f38c8f1bfc9727e15ce95c4c55f50815bfba From a1fea0f34989d1470f7382dc5f9513fa390051d8 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 11 Jul 2017 18:50:33 -0400 Subject: [PATCH 011/523] notes for code challenge github flow --- readme.md | 56 +++++++++++++++++++++---------------------------------- 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/readme.md b/readme.md index eee45fa..dbea404 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,5 @@ # CS1 - Lambda School Code Challenges - ## steps to ensuring your changes get pulled down -<<<<<<< HEAD 1. You will only need to run this step once ```console git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git @@ -28,49 +26,37 @@ upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges (fetch) upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges (push) ``` -2. Then, to get the changes from the origin (ryanhca) master, the srudents will need to run: +2. Then, to get the changes from the origin (ryanhca) master, the students will need to run: ```console $ git pull origin master ``` 3. These commands posted durig the Brown Bag - ```console - git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git - git pull upstream master - git remote -v +```console +git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git +git pull upstream master +git remote -v - git remote set-url upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges - // git push/commit etc. - ``` +git remote set-url upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges +// git push/commit etc. +``` 4. ...should be changed to: - ```console - $ git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git - $ git pull upstream master - $ git remote -v - - $ git remote set-url upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges - - // TO GET NEW CONTENT: - $ git pull origin master - // May require merge conflict resolution - - // STAGING FILES (git add) & MAKING LOCAL COMMITTS (git commit -m 'awesome message') STAYS THE SAME. - - // TO PUSH YOUR WORK TO YOUR GITHUB REPOSITORY: - git push upstream master - - // TO SUBMIT A PULL REQUEST TO RYAN'S (origin) GITHUB REPOSITORY, GO ONLINE TO https://github.com/ryanhca/CS1-Code-Challenges RYAN'S REPOSITORY AND SUBMIT A NEW PULL REQUEST - ``` -======= -- You will only need to run this step once +```console +$ git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git +$ git pull upstream master /* <---- This step only needs to be done once */ +$ git remote -v +$ git remote set-url upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges -1. git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git +// TO GET NEW CONTENT: +$ git pull origin master +// May require merge conflict resolution -- To get the changes to the repo each day run this +// STAGING FILES (git add) LOCALLY & MAKING LOCAL COMMITS (git commit -m 'awesome message') STAYS THE SAME. -2. git pull upstream master +// TO PUSH YOUR WORK TO YOUR GITHUB REPOSITORY: +git push upstream master -- You'll then have to resolve any merge conflicts that come up. Don't worry, you'll be pros at this after you're done and this is something that you'll have to do in the real world... all the time. :/ ->>>>>>> 9ec7f38c8f1bfc9727e15ce95c4c55f50815bfba +// TO SUBMIT A PULL REQUEST TO RYAN'S (origin) GITHUB REPOSITORY, GO ONLINE TO https://github.com/ryanhca/CS1-Code-Challenges RYAN'S REPOSITORY AND SUBMIT A NEW PULL REQUEST +``` From ebb269fe8e5a4edef65fe26869cb8ecf17c6a4cb Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 11 Jul 2017 18:53:48 -0400 Subject: [PATCH 012/523] notes for CS Code Challenge GitHub flow --- readme.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index dbea404..5409011 100644 --- a/readme.md +++ b/readme.md @@ -53,10 +53,16 @@ $ git remote set-url upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Cod $ git pull origin master // May require merge conflict resolution -// STAGING FILES (git add) LOCALLY & MAKING LOCAL COMMITS (git commit -m 'awesome message') STAYS THE SAME. +// STAGING FILES LOCALLY +$ git add +// MAKING LOCAL COMMITS +$ git commit -m 'awesome message' +// STAYS THE SAME. // TO PUSH YOUR WORK TO YOUR GITHUB REPOSITORY: -git push upstream master +$ git push upstream master -// TO SUBMIT A PULL REQUEST TO RYAN'S (origin) GITHUB REPOSITORY, GO ONLINE TO https://github.com/ryanhca/CS1-Code-Challenges RYAN'S REPOSITORY AND SUBMIT A NEW PULL REQUEST +// TO SUBMIT A PULL REQUEST TO RYAN'S (origin) GITHUB REPOSITORY, +// GO ONLINE TO https://github.com/ryanhca/CS1-Code-Challenges +// RYAN'S REPOSITORY AND SUBMIT A NEW PULL REQUEST ``` From f62ccb9f31294f608eab240539e789632c99976e Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 11 Jul 2017 18:54:44 -0400 Subject: [PATCH 013/523] notes for CS Code Challenge GitHub flow --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 5409011..ae5d1bd 100644 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git ``` -NOTE: VVVVVVVV I think this is incorrect VVVVVVVVV +NOTE: VVVVVVVV I think this is incorrect VVVVVVVVV 2. To get the changes to the repo each day run this ```console git pull upstream master From 6a30b9d509d8a62a437702b7f55d8233601c300d Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 11 Jul 2017 18:55:39 -0400 Subject: [PATCH 014/523] notes for CS Code Challenge GitHub flow --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index ae5d1bd..e5d1a72 100644 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git ``` -NOTE: VVVVVVVV I think this is incorrect VVVVVVVVV +**NOTE: I think this step is incorrect VVVVVVVVV** 2. To get the changes to the repo each day run this ```console git pull upstream master From 2b255e7a7ade6104e481c513428bc5e5676193c3 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 11 Jul 2017 18:56:43 -0400 Subject: [PATCH 015/523] notes for CS Code Challenge GitHub flow --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index e5d1a72..1c94b66 100644 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git ``` -**NOTE: I think this step is incorrect VVVVVVVVV** +**NOTE: I think this step is incorrect VVVVVVVVV** 2. To get the changes to the repo each day run this ```console git pull upstream master @@ -56,7 +56,7 @@ $ git pull origin master // STAGING FILES LOCALLY $ git add // MAKING LOCAL COMMITS -$ git commit -m 'awesome message' +$ git commit -m '' // STAYS THE SAME. // TO PUSH YOUR WORK TO YOUR GITHUB REPOSITORY: From 73bd800131223ddb558a7a7b894c067153ab5731 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 11 Jul 2017 18:57:27 -0400 Subject: [PATCH 016/523] notes for CS Code Challenge GitHub flow --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 1c94b66..6258ff5 100644 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git ``` -**NOTE: I think this step is incorrect VVVVVVVVV** +## NOTE: I think this step is incorrect 2. To get the changes to the repo each day run this ```console git pull upstream master From 971a73d82fa304bbe97d194c05cde18d5b9a54fa Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 11 Jul 2017 21:16:12 -0400 Subject: [PATCH 017/523] clarifying steps involved --- readme.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 6258ff5..c59c286 100644 --- a/readme.md +++ b/readme.md @@ -43,12 +43,20 @@ git remote set-url upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code- 4. ...should be changed to: ```console +// THESE TWO STEPS ONLY NEED TO BE DONE ONCE $ git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git -$ git pull upstream master /* <---- This step only needs to be done once */ +$ git pull upstream master + +// USE THIS TO SEE HOW YOUR ORIGIN AND UPSTREAM ARE CONFIGURED FOR FETCH AND PUSH $ git remote -v +// SET YOUR UPSTREAM TO YOUR GITHUB $ git remote set-url upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges +// CONFIRM THAT ORIGIN IS RYAN AND UPSTREAM IS YOUR GITHUB ACCOUNT +$ git remote -v + +// NOW, FOR EACH NEW CODING CHALLENGE // TO GET NEW CONTENT: $ git pull origin master // May require merge conflict resolution From f8ae8c8a5604cbcc2760bd487fdd76fd9575311e Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 12 Jul 2017 12:26:15 -0400 Subject: [PATCH 018/523] =?UTF-8?q?done=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reverseCase/reverseCase.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/reverseCase/reverseCase.js b/reverseCase/reverseCase.js index 93067ae..a87e931 100644 --- a/reverseCase/reverseCase.js +++ b/reverseCase/reverseCase.js @@ -5,3 +5,32 @@ */ +const reverseCase = function (str) { + // declare an array to house individual string letters or spaces in word/sentence order + const letters = []; + // declare a variable which will be used to reconstructed string + let caseConvertedString; + + // examine each letter in the string + for (let i = 0; i < str.length; i++) { + // uppercase or lowercase or a space? + // if a space, push space into temp holding array (if not a space, it's a letter) + if (str[i] === ' ') { + letters.push(str[i]); + // if already Upper Case, push lower Case version of letter into holding array + } else if (str[i] === str[i].toUpperCase()) { + letters.push(str[i].toLowerCase()) + // if not space and not already Upper Case, push Upper Case version of letter to holding array + } else letters.push(str[i].toUpperCase()) + } + // zip up the array of letters and spaces into a string + caseConvertedString = letters.join(''); + return caseConvertedString; +} + +const testCase1 = 'Fsdfsdf ESDFSDFdfsdfsdfsdfdsf'; +console.log(reverseCase(testCase1)); // ---> fSDFSDF esdfsdfDFSDFSDFSDFDSF + +// will it handle periods? +const testCase2 = 'The quick brown Mr. Fox jumped over the lazy Mr. Dog.'; +console.log(reverseCase(testCase2)); // ---> tHE QUICK BROWN mR. fOX JUMPED OVER THE LAZY mR. dOG. From aec3edc7a82b85e1a940f07ecc0f050f67b4ebb5 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 12 Jul 2017 12:34:05 -0400 Subject: [PATCH 019/523] reverseCase passes test cases --- reverseCase/reverseCase.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/reverseCase/reverseCase.js b/reverseCase/reverseCase.js index a87e931..e901193 100644 --- a/reverseCase/reverseCase.js +++ b/reverseCase/reverseCase.js @@ -4,7 +4,6 @@ * Assume that each string will contain only spaces and letters. */ - const reverseCase = function (str) { // declare an array to house individual string letters or spaces in word/sentence order const letters = []; @@ -28,9 +27,10 @@ const reverseCase = function (str) { return caseConvertedString; } -const testCase1 = 'Fsdfsdf ESDFSDFdfsdfsdfsdfdsf'; -console.log(reverseCase(testCase1)); // ---> fSDFSDF esdfsdfDFSDFSDFSDFDSF - +const testCase1 = 'Hello World' +console.log(reverseCase(testCase1)); // ---> hELLO wORLD +const testCase2 = 'Fsdfsdf ESDFSDFdfsdfsdfsdfdsf'; +console.log(reverseCase(testCase2)); // ---> fSDFSDF esdfsdfDFSDFSDFSDFDSF // will it handle periods? -const testCase2 = 'The quick brown Mr. Fox jumped over the lazy Mr. Dog.'; -console.log(reverseCase(testCase2)); // ---> tHE QUICK BROWN mR. fOX JUMPED OVER THE LAZY mR. dOG. +const testCase3 = 'The quick brown Mr. Fox jumped over the lazy Mr. Dog.'; +console.log(reverseCase(testCase3)); // ---> tHE QUICK BROWN mR. fOX JUMPED OVER THE LAZY mR. dOG. From e96af6443d61de27d470f092f79a4e4cb3cd78ff Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 13 Jul 2017 12:30:29 -0400 Subject: [PATCH 020/523] keeping this around for now --- readme.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/readme.md b/readme.md index 04cb236..c59c286 100644 --- a/readme.md +++ b/readme.md @@ -70,11 +70,7 @@ $ git commit -m '' // TO PUSH YOUR WORK TO YOUR GITHUB REPOSITORY: $ git push upstream master -<<<<<<< HEAD // TO SUBMIT A PULL REQUEST TO RYAN'S (origin) GITHUB REPOSITORY, // GO ONLINE TO https://github.com/ryanhca/CS1-Code-Challenges // RYAN'S REPOSITORY AND SUBMIT A NEW PULL REQUEST ``` -======= -- You'll then have to resolve any merge conflicts that come up. Don't worry, you'll be pros at this after you're done and this is something that you'll have to do in the real world... all the time. ->>>>>>> 16c30f05fda2a6621522f580bcc60d0ea35e639e From f6e2a7fe9cdd6f3997727ff2ae14f7ab8f34a242 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 13 Jul 2017 13:34:50 -0400 Subject: [PATCH 021/523] reverseCase passes test cases --- reverseCase/reverseCase.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/reverseCase/reverseCase.js b/reverseCase/reverseCase.js index e901193..b93bba2 100644 --- a/reverseCase/reverseCase.js +++ b/reverseCase/reverseCase.js @@ -34,3 +34,19 @@ console.log(reverseCase(testCase2)); // ---> fSDFSDF esdfsdfDFSDFSDFSDFDSF // will it handle periods? const testCase3 = 'The quick brown Mr. Fox jumped over the lazy Mr. Dog.'; console.log(reverseCase(testCase3)); // ---> tHE QUICK BROWN mR. fOX JUMPED OVER THE LAZY mR. dOG. + + +// // Latoyya's solution +// const reverseString = (str) => { +// let newString = ''; +// for (let i = 0; i < str.length; i++) { +// if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) { +// newString += str.charAt(i).toLowerCase(); +// } else { +// newString += str.charAt(i).toUpperCase(); +// } +// } +// return newString; +// }; +// console.log(reverseString('Hello World')); +// console.log(reverseString('Hello World My NamE is LAtoyYa SmitH')); From 5625bd34669b89987e67f2ab95bd2a00d030e24d Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 00:11:32 -0400 Subject: [PATCH 022/523] isPrime --- .../largestPrimePalindrome.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 1d15751..dc4563d 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -6,3 +6,33 @@ * Extra credit: Modify the function to look for the largest prime palindrome less than any provided number. * Extra credit 2: How can you improve the time complexity? (Google: Sieve of Eratosthenes) */ + + function isPrime(num) { + //return true if num is prime. + //otherwise return false + //hint: a prime number is only evenly divisible by itself and 1 + //hint2: you can solve this using a for loop + //note: 0 and 1 are NOT considered prime numbers + + // if (num < 2) {return false;} + // else if (num === 2) {return true;} + // else if (num % 2 === 0) {return false;} + // else if (num >= 3) { + // for (var i = 2; i < (num * .5); i++) { + // if (num % i === 0) { + // return false; + // } + // } + // } return true; + + if (num < 2) { + return false; + } + for (var i = 2; i <= num; i++) { + if ( num % i == 0 && i != num) { + return false; + } else { + return true; + } + } +} From 229afb887279a52dfa01c62c9d0c39a1a4719db3 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 00:34:50 -0400 Subject: [PATCH 023/523] isPalindrome to do: test odd vs even str.length --- .../largestPrimePalindrome.js | 62 +++++++++++-------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index dc4563d..4e151dc 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -7,32 +7,42 @@ * Extra credit 2: How can you improve the time complexity? (Google: Sieve of Eratosthenes) */ - function isPrime(num) { - //return true if num is prime. - //otherwise return false - //hint: a prime number is only evenly divisible by itself and 1 - //hint2: you can solve this using a for loop - //note: 0 and 1 are NOT considered prime numbers +function isPalindrome(str) { + for (let i = 0; i < str.length / 2; i++) { // <--- make sure divided by 2 handles odd and even length (floor vs. ceiling) + if (str[i] === str[-1 - i]) { + retrun true; + } else { + return false; + } + } +} + +function isPrime(num) { + //return true if num is prime. + //otherwise return false + //hint: a prime number is only evenly divisible by itself and 1 + //hint2: you can solve this using a for loop + //note: 0 and 1 are NOT considered prime numbers - // if (num < 2) {return false;} - // else if (num === 2) {return true;} - // else if (num % 2 === 0) {return false;} - // else if (num >= 3) { - // for (var i = 2; i < (num * .5); i++) { - // if (num % i === 0) { - // return false; - // } - // } - // } return true; + // if (num < 2) {return false;} + // else if (num === 2) {return true;} + // else if (num % 2 === 0) {return false;} + // else if (num >= 3) { + // for (var i = 2; i < (num * .5); i++) { + // if (num % i === 0) { + // return false; + // } + // } + // } return true; - if (num < 2) { - return false; - } - for (var i = 2; i <= num; i++) { - if ( num % i == 0 && i != num) { - return false; - } else { - return true; - } - } + if (num < 2) { + return false; + } + for (var i = 2; i <= num; i++) { + if ( num % i == 0 && i != num) { + return false; + } else { + return true; + } + } } From 064e34ee842cc171cff13af4d32675267a2863a5 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 00:38:50 -0400 Subject: [PATCH 024/523] to do: test both component functions --- .../largestPrimePalindrome.js | 23 ++++--------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 4e151dc..6ce0d39 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -8,6 +8,8 @@ */ function isPalindrome(str) { + // return true if string is a palindrome. + // otherwise return false for (let i = 0; i < str.length / 2; i++) { // <--- make sure divided by 2 handles odd and even length (floor vs. ceiling) if (str[i] === str[-1 - i]) { retrun true; @@ -18,27 +20,12 @@ function isPalindrome(str) { } function isPrime(num) { - //return true if num is prime. - //otherwise return false - //hint: a prime number is only evenly divisible by itself and 1 - //hint2: you can solve this using a for loop - //note: 0 and 1 are NOT considered prime numbers - - // if (num < 2) {return false;} - // else if (num === 2) {return true;} - // else if (num % 2 === 0) {return false;} - // else if (num >= 3) { - // for (var i = 2; i < (num * .5); i++) { - // if (num % i === 0) { - // return false; - // } - // } - // } return true; - + // return true if num is prime. + // otherwise return false if (num < 2) { return false; } - for (var i = 2; i <= num; i++) { + for (var i = 2; i <= num; i++) { // <-- i < num/2 or Math.sqrt(num) for speed if ( num % i == 0 && i != num) { return false; } else { From d3e41de9f4ebcbcfc7ec3d0e86109f5807d8027b Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 00:53:27 -0400 Subject: [PATCH 025/523] prime test cases --- largestPrimePalindrome/prime.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 largestPrimePalindrome/prime.js diff --git a/largestPrimePalindrome/prime.js b/largestPrimePalindrome/prime.js new file mode 100644 index 0000000..67c8aca --- /dev/null +++ b/largestPrimePalindrome/prime.js @@ -0,0 +1,33 @@ +function isPrime(num) { + // return true if num is prime. + // otherwise return false + if (num < 2) { + return false; + } + for (var i = 2; i <= num; i++) { // <-- i < num/2 or Math.sqrt(num) for speed + if ( num % i == 0 && i != num) { + return false; + } else { + return true; + } + } +} + +// 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, +) +console.log(`Q: 0 is prime? A: ${isPrime(0)}`) +console.log(`Q: 1 is prime? A: ${isPrime(1)}`) +console.log(`Q: 2 is prime? A: ${isPrime(2)}`) +console.log(`Q: 3 is prime? A: ${isPrime(3)}`) +console.log(`Q: 4 is prime? A: ${isPrime(4)}`) +console.log(`Q: 5 is prime? A: ${isPrime(5)}`) +console.log(`Q: 6 is prime? A: ${isPrime(6)}`) +console.log(`Q: 7 is prime? A: ${isPrime(7)}`) +console.log(`Q: 8 is prime? A: ${isPrime(8)}`) +console.log(`Q: 9 is prime? A: ${isPrime(9)}`) +console.log(`Q: 10 is prime? A: ${isPrime(10)}`) +console.log(`Q: 11 is prime? A: ${isPrime(11)}`) +console.log(`Q: 12 is prime? A: ${isPrime(12)}`) +console.log(`Q: 13 is prime? A: ${isPrime(13)}`) +console.log(`Q: 121 is prime? A: ${isPrime(121)}`) +console.log(`Q: 104729 is prime? A: ${isPrime(104729)}`) From 98cdee2db512314d8333c4c890cca7310e053f51 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 01:08:58 -0400 Subject: [PATCH 026/523] pass all test cases w/Math.sqrt() limit --- largestPrimePalindrome/palindrome.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 largestPrimePalindrome/palindrome.js diff --git a/largestPrimePalindrome/palindrome.js b/largestPrimePalindrome/palindrome.js new file mode 100644 index 0000000..f090c75 --- /dev/null +++ b/largestPrimePalindrome/palindrome.js @@ -0,0 +1,11 @@ +function isPalindrome(str) { + // return true if string is a palindrome. + // otherwise return false + for (let i = 0; i < str.length / 2; i++) { // <--- make sure divided by 2 handles odd and even length (floor vs. ceiling) + if (str[i] === str[-1 - i]) { + retrun true; + } else { + return false; + } + } +} From 5fcaa0a684f29079cb93176abfc35470b7a44aea Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 01:11:07 -0400 Subject: [PATCH 027/523] passes all tests w/Math.sqrt() --- largestPrimePalindrome/prime.js | 58 ++++++++++++++++----------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/largestPrimePalindrome/prime.js b/largestPrimePalindrome/prime.js index 67c8aca..f32aacb 100644 --- a/largestPrimePalindrome/prime.js +++ b/largestPrimePalindrome/prime.js @@ -1,33 +1,33 @@ -function isPrime(num) { - // return true if num is prime. - // otherwise return false - if (num < 2) { - return false; - } - for (var i = 2; i <= num; i++) { // <-- i < num/2 or Math.sqrt(num) for speed - if ( num % i == 0 && i != num) { - return false; - } else { - return true; +/* return true if num is prime. + otherwise return false */ + +const isPrime = function(num) { + if (num < 2) {return false;} + else if (num === 2) {return true;} + else if (num % 2 === 0) {return false;} + else if (num >= 3) { + for (var i = 2; i < Math.sqrt(num + 1); i++) { // Maybe a ceiling would work better (but slower?)? + if (num % i === 0) { + return false; + } } - } + } return true; } // 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, -) -console.log(`Q: 0 is prime? A: ${isPrime(0)}`) -console.log(`Q: 1 is prime? A: ${isPrime(1)}`) -console.log(`Q: 2 is prime? A: ${isPrime(2)}`) -console.log(`Q: 3 is prime? A: ${isPrime(3)}`) -console.log(`Q: 4 is prime? A: ${isPrime(4)}`) -console.log(`Q: 5 is prime? A: ${isPrime(5)}`) -console.log(`Q: 6 is prime? A: ${isPrime(6)}`) -console.log(`Q: 7 is prime? A: ${isPrime(7)}`) -console.log(`Q: 8 is prime? A: ${isPrime(8)}`) -console.log(`Q: 9 is prime? A: ${isPrime(9)}`) -console.log(`Q: 10 is prime? A: ${isPrime(10)}`) -console.log(`Q: 11 is prime? A: ${isPrime(11)}`) -console.log(`Q: 12 is prime? A: ${isPrime(12)}`) -console.log(`Q: 13 is prime? A: ${isPrime(13)}`) -console.log(`Q: 121 is prime? A: ${isPrime(121)}`) -console.log(`Q: 104729 is prime? A: ${isPrime(104729)}`) +console.log(`Q: 0 is prime? A: ${isPrime(0)}`) // <--- false +console.log(`Q: 1 is prime? A: ${isPrime(1)}`) // <--- false +console.log(`Q: 2 is prime? A: ${isPrime(2)}`) // <--- true +console.log(`Q: 3 is prime? A: ${isPrime(3)}`) // <--- true +console.log(`Q: 4 is prime? A: ${isPrime(4)}`) // <--- false +console.log(`Q: 5 is prime? A: ${isPrime(5)}`) // <--- true +console.log(`Q: 6 is prime? A: ${isPrime(6)}`) // <--- false +console.log(`Q: 7 is prime? A: ${isPrime(7)}`) // <--- true +console.log(`Q: 8 is prime? A: ${isPrime(8)}`) // <--- false +console.log(`Q: 9 is prime? A: ${isPrime(9)}`) // <--- false +console.log(`Q: 10 is prime? A: ${isPrime(10)}`) // <--- false +console.log(`Q: 11 is prime? A: ${isPrime(11)}`) // <--- true +console.log(`Q: 12 is prime? A: ${isPrime(12)}`) // <--- false +console.log(`Q: 13 is prime? A: ${isPrime(13)}`) // <--- true +console.log(`Q: 121 is prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) +console.log(`Q: 104729 is prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) From 223e086cb5212fe7b75f7ff9851dcbd78b7d607b Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 01:13:37 -0400 Subject: [PATCH 028/523] prime time --- .../largestPrimePalindrome.js | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 6ce0d39..af9748c 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -7,16 +7,20 @@ * Extra credit 2: How can you improve the time complexity? (Google: Sieve of Eratosthenes) */ -function isPalindrome(str) { - // return true if string is a palindrome. - // otherwise return false - for (let i = 0; i < str.length / 2; i++) { // <--- make sure divided by 2 handles odd and even length (floor vs. ceiling) - if (str[i] === str[-1 - i]) { - retrun true; - } else { - return false; + /* return true if num is prime. + otherwise return false */ + +const isPrime = function(num) { + if (num < 2) {return false;} + else if (num === 2) {return true;} + else if (num % 2 === 0) {return false;} + else if (num >= 3) { + for (var i = 2; i < Math.sqrt(num + 1); i++) { // Maybe a ceiling would work better (but slower?)? + if (num % i === 0) { + return false; + } } - } + } return true; } function isPrime(num) { From b7cb8aa14e2c77fcfacded26265a964c8bfd00a4 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 01:28:05 -0400 Subject: [PATCH 029/523] all palindrome test cases pass --- largestPrimePalindrome/palindrome.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/largestPrimePalindrome/palindrome.js b/largestPrimePalindrome/palindrome.js index f090c75..585c2e3 100644 --- a/largestPrimePalindrome/palindrome.js +++ b/largestPrimePalindrome/palindrome.js @@ -2,10 +2,17 @@ function isPalindrome(str) { // return true if string is a palindrome. // otherwise return false for (let i = 0; i < str.length / 2; i++) { // <--- make sure divided by 2 handles odd and even length (floor vs. ceiling) - if (str[i] === str[-1 - i]) { - retrun true; + if (str[i] === str[str.length - 1 - i]) { + return true; } else { return false; } } } + +console.log(`Q: Is 'palindrome' a palindrome? A: ${isPalindrome('palindrome')}`) // <-- false +console.log(`Q: Is ' ' a palindrome? A: ${isPalindrome(' ')}`) // <-- true +console.log(`Q: Is 'a' a palindrome? A: ${isPalindrome('a')}`) // <-- true +console.log(`Q: Is 'bb' a palindrome? A: ${isPalindrome('bb')}`) // <-- true +console.log(`Q: Is 'cdc' a palindrome? A: ${isPalindrome('cdc')}`) // <-- true +console.log(`Q: Is 'amanaplanacanalpanama' a palindrome? A: ${isPalindrome('amanaplanacanalpanama')}`) // <-- true From 9f4a1aa1364b137bbaadfc7a696df5151e6cd489 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 01:29:05 -0400 Subject: [PATCH 030/523] prime and palindrome ready --- largestPrimePalindrome/largestPrimePalindrome.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index af9748c..960518f 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -23,17 +23,14 @@ const isPrime = function(num) { } return true; } -function isPrime(num) { - // return true if num is prime. +function isPalindrome(str) { + // return true if string is a palindrome. // otherwise return false - if (num < 2) { - return false; - } - for (var i = 2; i <= num; i++) { // <-- i < num/2 or Math.sqrt(num) for speed - if ( num % i == 0 && i != num) { - return false; - } else { + for (let i = 0; i < str.length / 2; i++) { // <--- make sure divided by 2 handles odd and even length (floor vs. ceiling) + if (str[i] === str[str.length - 1 - i]) { return true; + } else { + return false; } } } From 7cd0651bec79062f95f52933e5739accd00bada3 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 01:30:48 -0400 Subject: [PATCH 031/523] prime time --- largestPrimePalindrome/prime.js | 1 + 1 file changed, 1 insertion(+) diff --git a/largestPrimePalindrome/prime.js b/largestPrimePalindrome/prime.js index f32aacb..0dc1c00 100644 --- a/largestPrimePalindrome/prime.js +++ b/largestPrimePalindrome/prime.js @@ -14,6 +14,7 @@ const isPrime = function(num) { } return true; } +// PRIME TEST SUITE // 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, console.log(`Q: 0 is prime? A: ${isPrime(0)}`) // <--- false console.log(`Q: 1 is prime? A: ${isPrime(1)}`) // <--- false From 1946af08d47484375aa217445c927f1d0682ecdf Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 01:30:57 -0400 Subject: [PATCH 032/523] palindrome test suite all pass --- largestPrimePalindrome/palindrome.js | 1 + 1 file changed, 1 insertion(+) diff --git a/largestPrimePalindrome/palindrome.js b/largestPrimePalindrome/palindrome.js index 585c2e3..590b541 100644 --- a/largestPrimePalindrome/palindrome.js +++ b/largestPrimePalindrome/palindrome.js @@ -10,6 +10,7 @@ function isPalindrome(str) { } } +// PALINDROME TEST SUITE console.log(`Q: Is 'palindrome' a palindrome? A: ${isPalindrome('palindrome')}`) // <-- false console.log(`Q: Is ' ' a palindrome? A: ${isPalindrome(' ')}`) // <-- true console.log(`Q: Is 'a' a palindrome? A: ${isPalindrome('a')}`) // <-- true From ce8bf6442d81435c7506e2fea539576325dbf40b Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 01:31:09 -0400 Subject: [PATCH 033/523] added test suite to verify --- .../largestPrimePalindrome.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 960518f..0e4413c 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -34,3 +34,28 @@ function isPalindrome(str) { } } } +// PALINDROME TEST SUITE +console.log(`Q: Is 'palindrome' a palindrome? A: ${isPalindrome('palindrome')}`) // <-- false +console.log(`Q: Is ' ' a palindrome? A: ${isPalindrome(' ')}`) // <-- true +console.log(`Q: Is 'a' a palindrome? A: ${isPalindrome('a')}`) // <-- true +console.log(`Q: Is 'bb' a palindrome? A: ${isPalindrome('bb')}`) // <-- true +console.log(`Q: Is 'cdc' a palindrome? A: ${isPalindrome('cdc')}`) // <-- true +console.log(`Q: Is 'amanaplanacanalpanama' a palindrome? A: ${isPalindrome('amanaplanacanalpanama')}`) // <-- true +// PRIME TEST SUITE +// 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, +console.log(`Q: 0 is prime? A: ${isPrime(0)}`) // <--- false +console.log(`Q: 1 is prime? A: ${isPrime(1)}`) // <--- false +console.log(`Q: 2 is prime? A: ${isPrime(2)}`) // <--- true +console.log(`Q: 3 is prime? A: ${isPrime(3)}`) // <--- true +console.log(`Q: 4 is prime? A: ${isPrime(4)}`) // <--- false +console.log(`Q: 5 is prime? A: ${isPrime(5)}`) // <--- true +console.log(`Q: 6 is prime? A: ${isPrime(6)}`) // <--- false +console.log(`Q: 7 is prime? A: ${isPrime(7)}`) // <--- true +console.log(`Q: 8 is prime? A: ${isPrime(8)}`) // <--- false +console.log(`Q: 9 is prime? A: ${isPrime(9)}`) // <--- false +console.log(`Q: 10 is prime? A: ${isPrime(10)}`) // <--- false +console.log(`Q: 11 is prime? A: ${isPrime(11)}`) // <--- true +console.log(`Q: 12 is prime? A: ${isPrime(12)}`) // <--- false +console.log(`Q: 13 is prime? A: ${isPrime(13)}`) // <--- true +console.log(`Q: 121 is prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) +console.log(`Q: 104729 is prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) From 1775ebf54ddfc7bc5336ec7044ccd89f637e6607 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 01:32:27 -0400 Subject: [PATCH 034/523] prime and palindrome functions --- largestPrimePalindrome/largestPrimePalindrome.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 0e4413c..34725c4 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -6,11 +6,9 @@ * Extra credit: Modify the function to look for the largest prime palindrome less than any provided number. * Extra credit 2: How can you improve the time complexity? (Google: Sieve of Eratosthenes) */ - - /* return true if num is prime. - otherwise return false */ - const isPrime = function(num) { + // return true if num is prime. + // otherwise return false if (num < 2) {return false;} else if (num === 2) {return true;} else if (num % 2 === 0) {return false;} @@ -23,7 +21,7 @@ const isPrime = function(num) { } return true; } -function isPalindrome(str) { +const isPalindrome function(str) { // return true if string is a palindrome. // otherwise return false for (let i = 0; i < str.length / 2; i++) { // <--- make sure divided by 2 handles odd and even length (floor vs. ceiling) From e474123e66855f0264aed0c8d64d768db0f71fc4 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 01:33:39 -0400 Subject: [PATCH 035/523] all tests pass! --- largestPrimePalindrome/largestPrimePalindrome.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 34725c4..785861a 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -21,7 +21,7 @@ const isPrime = function(num) { } return true; } -const isPalindrome function(str) { +const isPalindrome = function(str) { // return true if string is a palindrome. // otherwise return false for (let i = 0; i < str.length / 2; i++) { // <--- make sure divided by 2 handles odd and even length (floor vs. ceiling) From 5e94efad4f9448c67c9d3ce94b74d7dba1926e23 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 11:46:51 -0400 Subject: [PATCH 036/523] roadmap --- .../largestPrimePalindrome.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 785861a..a89b987 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -6,6 +6,36 @@ * Extra credit: Modify the function to look for the largest prime palindrome less than any provided number. * Extra credit 2: How can you improve the time complexity? (Google: Sieve of Eratosthenes) */ + +// returns largest prime palindrome +const largestPrimePalindrome = function(num) { + return findPrimePals(findPrimes(num))[-1] // <--- JS doesn't support -1 as array tail :() +} + +// evaluates a range of natural numbers +// I: largest number in range (inclusive) +// O; an array of ALL prime #'s from range 0 thru input integer +const findPrimes = function(*num) { + const primes = []; + for number in range 0 thru *num + if (**isPrime(*num)), then add to *primes + return *primes; + } + +// const findLargestPrime = function(*arrOfPrimes, e.g. findPrimes(###)) { +// return (*arrOfPrimes[*arrOfPrimes - 1]) // <--- last item in array will be largest prime +// } + +// I: a sorted array of prime numbers, smallest to largest +// O: array of prime Palindromes +const findPrimePals = function(*anArrOfPrimes, e.g. findPrimes(###)) { + const primePals = [] + for (i=0;i Date: Fri, 14 Jul 2017 12:07:34 -0400 Subject: [PATCH 037/523] component to find prime numbers in a range --- largestPrimePalindrome/findPrimes.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 largestPrimePalindrome/findPrimes.js diff --git a/largestPrimePalindrome/findPrimes.js b/largestPrimePalindrome/findPrimes.js new file mode 100644 index 0000000..e69de29 From bc7c516b5a8e83cf1d6c0796b5f66662daf43393 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:10:00 -0400 Subject: [PATCH 038/523] findPrime() will invoke isPrime() --- largestPrimePalindrome/findPrimes.js | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/largestPrimePalindrome/findPrimes.js b/largestPrimePalindrome/findPrimes.js index e69de29..8e02f19 100644 --- a/largestPrimePalindrome/findPrimes.js +++ b/largestPrimePalindrome/findPrimes.js @@ -0,0 +1,43 @@ +// evaluates a range of natural numbers +// I: largest number in range (inclusive) +// O; an array of ALL prime #'s from range 0 thru input integer +const findPrimes = function(*num) { + const primes = []; + for number in range 0 thru *num + if (**isPrime(*num)), then add to *primes + return *primes; + } + +const isPrime = function(num) { + // return true if num is prime. + // otherwise return false + if (num < 2) {return false;} + else if (num === 2) {return true;} + else if (num % 2 === 0) {return false;} + else if (num >= 3) { + for (var i = 2; i < Math.sqrt(num + 1); i++) { // Maybe a ceiling would work better (but slower?)? + if (num % i === 0) { + return false; + } + } + } return true; +} + +// PRIME TEST SUITE +// 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, +console.log(`Q: 0 is prime? A: ${isPrime(0)}`) // <--- false +console.log(`Q: 1 is prime? A: ${isPrime(1)}`) // <--- false +console.log(`Q: 2 is prime? A: ${isPrime(2)}`) // <--- true +console.log(`Q: 3 is prime? A: ${isPrime(3)}`) // <--- true +console.log(`Q: 4 is prime? A: ${isPrime(4)}`) // <--- false +console.log(`Q: 5 is prime? A: ${isPrime(5)}`) // <--- true +console.log(`Q: 6 is prime? A: ${isPrime(6)}`) // <--- false +console.log(`Q: 7 is prime? A: ${isPrime(7)}`) // <--- true +console.log(`Q: 8 is prime? A: ${isPrime(8)}`) // <--- false +console.log(`Q: 9 is prime? A: ${isPrime(9)}`) // <--- false +console.log(`Q: 10 is prime? A: ${isPrime(10)}`) // <--- false +console.log(`Q: 11 is prime? A: ${isPrime(11)}`) // <--- true +console.log(`Q: 12 is prime? A: ${isPrime(12)}`) // <--- false +console.log(`Q: 13 is prime? A: ${isPrime(13)}`) // <--- true +console.log(`Q: 121 is prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) +console.log(`Q: 104729 is prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) From 165b6678be6d2fdcedeb898b62b7566eb1a62950 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:14:24 -0400 Subject: [PATCH 039/523] findPrimes test suite --- largestPrimePalindrome/findPrimes.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/largestPrimePalindrome/findPrimes.js b/largestPrimePalindrome/findPrimes.js index 8e02f19..8ba1c75 100644 --- a/largestPrimePalindrome/findPrimes.js +++ b/largestPrimePalindrome/findPrimes.js @@ -1,11 +1,13 @@ // evaluates a range of natural numbers // I: largest number in range (inclusive) // O; an array of ALL prime #'s from range 0 thru input integer -const findPrimes = function(*num) { +const findPrimes = function(bigNum) { const primes = []; - for number in range 0 thru *num - if (**isPrime(*num)), then add to *primes - return *primes; + // for number in range 0 thru *num + for (i = 0; i <=bigNum; i++) { + if (isPrime(bigNum)) primes.push(isPrime(bigNum)); + } + return primes; } const isPrime = function(num) { @@ -23,8 +25,9 @@ const isPrime = function(num) { } return true; } -// PRIME TEST SUITE -// 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, + +// isPrime TEST SUITE +// 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, console.log(`Q: 0 is prime? A: ${isPrime(0)}`) // <--- false console.log(`Q: 1 is prime? A: ${isPrime(1)}`) // <--- false console.log(`Q: 2 is prime? A: ${isPrime(2)}`) // <--- true @@ -41,3 +44,7 @@ console.log(`Q: 12 is prime? A: ${isPrime(12)}`) // <--- false console.log(`Q: 13 is prime? A: ${isPrime(13)}`) // <--- true console.log(`Q: 121 is prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) console.log(`Q: 104729 is prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) + +// findPrimes TEST SUITE +// [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113] +console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(121)}`); From 174a3f0b674ea1b61568f35a6ee9c5b31c2859bf Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:17:50 -0400 Subject: [PATCH 040/523] =?UTF-8?q?findPrimes=20test=20case=20passes=20?= =?UTF-8?q?=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- largestPrimePalindrome/findPrimes.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/largestPrimePalindrome/findPrimes.js b/largestPrimePalindrome/findPrimes.js index 8ba1c75..a374254 100644 --- a/largestPrimePalindrome/findPrimes.js +++ b/largestPrimePalindrome/findPrimes.js @@ -5,7 +5,7 @@ const findPrimes = function(bigNum) { const primes = []; // for number in range 0 thru *num for (i = 0; i <=bigNum; i++) { - if (isPrime(bigNum)) primes.push(isPrime(bigNum)); + if (isPrime(i)) primes.push(i); } return primes; } @@ -27,7 +27,7 @@ const isPrime = function(num) { // isPrime TEST SUITE -// 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, +// 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, console.log(`Q: 0 is prime? A: ${isPrime(0)}`) // <--- false console.log(`Q: 1 is prime? A: ${isPrime(1)}`) // <--- false console.log(`Q: 2 is prime? A: ${isPrime(2)}`) // <--- true @@ -46,5 +46,5 @@ console.log(`Q: 121 is prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = console.log(`Q: 104729 is prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) // findPrimes TEST SUITE -// [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113] -console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(121)}`); +// [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127] +console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(127)}`); From 5c4c51a8e799eb394df643ce4b72c08d8edfbdb3 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:20:00 -0400 Subject: [PATCH 041/523] =?UTF-8?q?finsPrimes=20test=20case=20passes=20up?= =?UTF-8?q?=20to=2010,000=20prime=20numbers=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- largestPrimePalindrome/findPrimes.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/largestPrimePalindrome/findPrimes.js b/largestPrimePalindrome/findPrimes.js index a374254..40a6550 100644 --- a/largestPrimePalindrome/findPrimes.js +++ b/largestPrimePalindrome/findPrimes.js @@ -48,3 +48,5 @@ console.log(`Q: 104729 is prime? A: ${isPrime(104729)}`)// <--- true (104,729 is // findPrimes TEST SUITE // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127] console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(127)}`); +// console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(104729)}`); // <--- 10,000 prime numbers!!!! +console.log(findPrimes(104729).length); From 96f3027f2b0ede0b6cf79c63185f1dce92e3be51 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:21:46 -0400 Subject: [PATCH 042/523] added findPrimes component --- largestPrimePalindrome/largestPrimePalindrome.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index a89b987..a283909 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -15,12 +15,14 @@ const largestPrimePalindrome = function(num) { // evaluates a range of natural numbers // I: largest number in range (inclusive) // O; an array of ALL prime #'s from range 0 thru input integer -const findPrimes = function(*num) { +const findPrimes = function(bigNum) { const primes = []; - for number in range 0 thru *num - if (**isPrime(*num)), then add to *primes - return *primes; + // for number in range 0 thru *num + for (i = 0; i <=bigNum; i++) { + if (isPrime(i)) primes.push(i); } + return primes; +} // const findLargestPrime = function(*arrOfPrimes, e.g. findPrimes(###)) { // return (*arrOfPrimes[*arrOfPrimes - 1]) // <--- last item in array will be largest prime From f5f451f667631c8a3e2eac2a18c466b1348cc38d Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:22:30 -0400 Subject: [PATCH 043/523] component to find prime palindromes from array of primes --- largestPrimePalindrome/findPrimePalindromes.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 largestPrimePalindrome/findPrimePalindromes.js diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js new file mode 100644 index 0000000..e69de29 From 5288c7831d225e987eb0d59b90150612fc29291a Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:24:06 -0400 Subject: [PATCH 044/523] components w/their Test Suites --- .../findPrimePalindromes.js | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index e69de29..6c4878c 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -0,0 +1,79 @@ +// I: a sorted array of prime numbers, smallest to largest +// O: array of prime Palindromes +const findPrimePals = function(*anArrOfPrimes, e.g. findPrimes(###)) { + const primePals = [] + for (i=0;i= 3) { + for (var i = 2; i < Math.sqrt(num + 1); i++) { // Maybe a ceiling would work better (but slower?)? + if (num % i === 0) { + return false; + } + } + } return true; +} + +const isPalindrome = function(str) { + // return true if string is a palindrome. + // otherwise return false + for (let i = 0; i < str.length / 2; i++) { // <--- make sure divided by 2 handles odd and even length (floor vs. ceiling) + if (str[i] === str[str.length - 1 - i]) { + return true; + } else { + return false; + } + } +} +// PALINDROME TEST SUITE +console.log(`Q: Is 'palindrome' a palindrome? A: ${isPalindrome('palindrome')}`) // <-- false +console.log(`Q: Is ' ' a palindrome? A: ${isPalindrome(' ')}`) // <-- true +console.log(`Q: Is 'a' a palindrome? A: ${isPalindrome('a')}`) // <-- true +console.log(`Q: Is 'bb' a palindrome? A: ${isPalindrome('bb')}`) // <-- true +console.log(`Q: Is 'cdc' a palindrome? A: ${isPalindrome('cdc')}`) // <-- true +console.log(`Q: Is 'amanaplanacanalpanama' a palindrome? A: ${isPalindrome('amanaplanacanalpanama')}`) // <-- true +// isPrime TEST SUITE +// 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, +console.log(`Q: 0 is prime? A: ${isPrime(0)}`) // <--- false +console.log(`Q: 1 is prime? A: ${isPrime(1)}`) // <--- false +console.log(`Q: 2 is prime? A: ${isPrime(2)}`) // <--- true +console.log(`Q: 3 is prime? A: ${isPrime(3)}`) // <--- true +console.log(`Q: 4 is prime? A: ${isPrime(4)}`) // <--- false +console.log(`Q: 5 is prime? A: ${isPrime(5)}`) // <--- true +console.log(`Q: 6 is prime? A: ${isPrime(6)}`) // <--- false +console.log(`Q: 7 is prime? A: ${isPrime(7)}`) // <--- true +console.log(`Q: 8 is prime? A: ${isPrime(8)}`) // <--- false +console.log(`Q: 9 is prime? A: ${isPrime(9)}`) // <--- false +console.log(`Q: 10 is prime? A: ${isPrime(10)}`) // <--- false +console.log(`Q: 11 is prime? A: ${isPrime(11)}`) // <--- true +console.log(`Q: 12 is prime? A: ${isPrime(12)}`) // <--- false +console.log(`Q: 13 is prime? A: ${isPrime(13)}`) // <--- true +console.log(`Q: 121 is prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) +console.log(`Q: 104729 is prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) +// findPrimes TEST SUITE +// [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127] +console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(127)}`); +// console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(104729)}`); // <--- 10,000 prime numbers!!!! +console.log(findPrimes(104729).length); From d7833e18f56cf5ff187b9a11c33b4d3f39c64709 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:25:13 -0400 Subject: [PATCH 045/523] compilation confirmed --- largestPrimePalindrome/findPrimePalindromes.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index 6c4878c..20fe40a 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -1,12 +1,12 @@ // I: a sorted array of prime numbers, smallest to largest // O: array of prime Palindromes -const findPrimePals = function(*anArrOfPrimes, e.g. findPrimes(###)) { - const primePals = [] - for (i=0;i Date: Fri, 14 Jul 2017 12:28:07 -0400 Subject: [PATCH 046/523] description comments --- .../findPrimePalindromes.js | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index 20fe40a..3a48497 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -1,17 +1,17 @@ // I: a sorted array of prime numbers, smallest to largest -// O: array of prime Palindromes -// const findPrimePals = function(*anArrOfPrimes, e.g. findPrimes(###)) { -// const primePals = [] -// for (i=0;i Date: Fri, 14 Jul 2017 12:29:02 -0400 Subject: [PATCH 047/523] same --- largestPrimePalindrome/findPrimePalindromes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index 3a48497..e8662e0 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -38,7 +38,7 @@ const isPrime = function(num) { } return true; } -// I: any string +// I: any string NOTE: handles integers as well √ // O: "true" if INPUT is a palindrome const isPalindrome = function(str) { // return true if string is a palindrome. From 24f96bbd31ad3d035cf89ef79637230dfc1f86c4 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:31:29 -0400 Subject: [PATCH 048/523] rough --- largestPrimePalindrome/findPrimePalindromes.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index e8662e0..be9546f 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -1,14 +1,13 @@ // I: a sorted array of prime numbers, smallest to largest // O: array of prime palindromes -const findPrimePals = function(*anArrOfPrimes, e.g. findPrimes(###)) { +const findPrimePals = function(primeArr) { const primePals = [] - for (i=0;i Date: Fri, 14 Jul 2017 12:32:49 -0400 Subject: [PATCH 049/523] ibid --- largestPrimePalindrome/findPrimePalindromes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index be9546f..fb7f923 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -1,9 +1,9 @@ // I: a sorted array of prime numbers, smallest to largest // O: array of prime palindromes const findPrimePals = function(primeArr) { - const primePals = [] + const primePalsArr = [] for (i = 0; i < primeArr.length; i++) { - if (isPalindrome(primeArr[i])) primePals.push(anArrOfPrimes[i]) + if (isPalindrome(primeArr[i])) primePalsArr.push(primeArr[i]) } return primePals; } From d1d2f9b59e36b2fc6b6774cf61867474c48c2799 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:34:34 -0400 Subject: [PATCH 050/523] test suite --- largestPrimePalindrome/findPrimePalindromes.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index fb7f923..1329ad7 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -80,3 +80,6 @@ console.log(`Q: 104729 is prime? A: ${isPrime(104729)}`)// <--- true (104,729 is console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(127)}`); // console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(104729)}`); // <--- 10,000 prime numbers!!!! console.log(findPrimes(104729).length); +// findPrimes TEST SUITE +// [11, 101, ...] +console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${findPrimePals(127)}`); From bc2a98264027216747e09733be1ba1f1393639df Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:35:09 -0400 Subject: [PATCH 051/523] ibid --- largestPrimePalindrome/findPrimePalindromes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index 1329ad7..779da23 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -5,7 +5,7 @@ const findPrimePals = function(primeArr) { for (i = 0; i < primeArr.length; i++) { if (isPalindrome(primeArr[i])) primePalsArr.push(primeArr[i]) } - return primePals; + return primePalsArr; } // evaluates a range of natural numbers From 284de046ab2772829476683da52d1a0c1c5a68fa Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:35:42 -0400 Subject: [PATCH 052/523] ibid --- largestPrimePalindrome/findPrimePalindromes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index 779da23..37b6e22 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -77,7 +77,7 @@ console.log(`Q: 121 is prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = console.log(`Q: 104729 is prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) // findPrimes TEST SUITE // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127] -console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(127)}`); +console.log(`Q: what are the primes from 0 to 127?\nA: ${findPrimes(127)}`); // console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(104729)}`); // <--- 10,000 prime numbers!!!! console.log(findPrimes(104729).length); // findPrimes TEST SUITE From d7b8040b000b82cabadca1f5bc5fb7c7a2591713 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:38:15 -0400 Subject: [PATCH 053/523] ibid --- .../findPrimePalindromes.js | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index 37b6e22..d4fd6be 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -59,22 +59,22 @@ console.log(`Q: Is 'cdc' a palindrome? A: ${isPalindrome('cdc' console.log(`Q: Is 'amanaplanacanalpanama' a palindrome? A: ${isPalindrome('amanaplanacanalpanama')}`) // <-- true // isPrime TEST SUITE // 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, -console.log(`Q: 0 is prime? A: ${isPrime(0)}`) // <--- false -console.log(`Q: 1 is prime? A: ${isPrime(1)}`) // <--- false -console.log(`Q: 2 is prime? A: ${isPrime(2)}`) // <--- true -console.log(`Q: 3 is prime? A: ${isPrime(3)}`) // <--- true -console.log(`Q: 4 is prime? A: ${isPrime(4)}`) // <--- false -console.log(`Q: 5 is prime? A: ${isPrime(5)}`) // <--- true -console.log(`Q: 6 is prime? A: ${isPrime(6)}`) // <--- false -console.log(`Q: 7 is prime? A: ${isPrime(7)}`) // <--- true -console.log(`Q: 8 is prime? A: ${isPrime(8)}`) // <--- false -console.log(`Q: 9 is prime? A: ${isPrime(9)}`) // <--- false -console.log(`Q: 10 is prime? A: ${isPrime(10)}`) // <--- false -console.log(`Q: 11 is prime? A: ${isPrime(11)}`) // <--- true -console.log(`Q: 12 is prime? A: ${isPrime(12)}`) // <--- false -console.log(`Q: 13 is prime? A: ${isPrime(13)}`) // <--- true -console.log(`Q: 121 is prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) -console.log(`Q: 104729 is prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) +console.log(`Q: Is 0 prime? A: ${isPrime(0)}`) // <--- false +console.log(`Q: Is 1 prime? A: ${isPrime(1)}`) // <--- false +console.log(`Q: Is 2 prime? A: ${isPrime(2)}`) // <--- true +console.log(`Q: Is 3 prime? A: ${isPrime(3)}`) // <--- true +console.log(`Q: Is 4 prime? A: ${isPrime(4)}`) // <--- false +console.log(`Q: Is 5 prime? A: ${isPrime(5)}`) // <--- true +console.log(`Q: Is 6 prime? A: ${isPrime(6)}`) // <--- false +console.log(`Q: Is 7 prime? A: ${isPrime(7)}`) // <--- true +console.log(`Q: Is 8 prime? A: ${isPrime(8)}`) // <--- false +console.log(`Q: Is 9 prime? A: ${isPrime(9)}`) // <--- false +console.log(`Q: Is 10 prime? A: ${isPrime(10)}`) // <--- false +console.log(`Q: Is 11 prime? A: ${isPrime(11)}`) // <--- true +console.log(`Q: Is 12 prime? A: ${isPrime(12)}`) // <--- false +console.log(`Q: Is 13 prime? A: ${isPrime(13)}`) // <--- true +console.log(`Q: Is 121 prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) +console.log(`Q: Is 104729 prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) // findPrimes TEST SUITE // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127] console.log(`Q: what are the primes from 0 to 127?\nA: ${findPrimes(127)}`); From 04237949a45480be8f4a61a84949a25f4c97ce33 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:39:47 -0400 Subject: [PATCH 054/523] file name changes --- largestPrimePalindrome/{palindrome.js => isPalindrome.js} | 0 largestPrimePalindrome/{prime.js => isPrime.js} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename largestPrimePalindrome/{palindrome.js => isPalindrome.js} (100%) rename largestPrimePalindrome/{prime.js => isPrime.js} (100%) diff --git a/largestPrimePalindrome/palindrome.js b/largestPrimePalindrome/isPalindrome.js similarity index 100% rename from largestPrimePalindrome/palindrome.js rename to largestPrimePalindrome/isPalindrome.js diff --git a/largestPrimePalindrome/prime.js b/largestPrimePalindrome/isPrime.js similarity index 100% rename from largestPrimePalindrome/prime.js rename to largestPrimePalindrome/isPrime.js From 73ce826bc4783242ba14fd28c8d2a4f8e05dd9a0 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:41:01 -0400 Subject: [PATCH 055/523] testing for number handling --- largestPrimePalindrome/isPalindrome.js | 1 + 1 file changed, 1 insertion(+) diff --git a/largestPrimePalindrome/isPalindrome.js b/largestPrimePalindrome/isPalindrome.js index 590b541..56fe76a 100644 --- a/largestPrimePalindrome/isPalindrome.js +++ b/largestPrimePalindrome/isPalindrome.js @@ -17,3 +17,4 @@ console.log(`Q: Is 'a' a palindrome? A: ${isPalindrome('a')} console.log(`Q: Is 'bb' a palindrome? A: ${isPalindrome('bb')}`) // <-- true console.log(`Q: Is 'cdc' a palindrome? A: ${isPalindrome('cdc')}`) // <-- true console.log(`Q: Is 'amanaplanacanalpanama' a palindrome? A: ${isPalindrome('amanaplanacanalpanama')}`) // <-- true +console.log(`Q: Is an integer a palindrome? A: ${isPalindrome(5)}`) // <-- ??? From 60d437c902a0221e7da6173bba332be9a3249e6f Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:47:21 -0400 Subject: [PATCH 056/523] =?UTF-8?q?numToStr=20Test=20suite=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- largestPrimePalindrome/isPalindrome.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/largestPrimePalindrome/isPalindrome.js b/largestPrimePalindrome/isPalindrome.js index 56fe76a..e1f1780 100644 --- a/largestPrimePalindrome/isPalindrome.js +++ b/largestPrimePalindrome/isPalindrome.js @@ -10,11 +10,19 @@ function isPalindrome(str) { } } -// PALINDROME TEST SUITE +const numToStr = function(num) { + return `${num}`; +} + +// isPalindrome() TEST SUITE console.log(`Q: Is 'palindrome' a palindrome? A: ${isPalindrome('palindrome')}`) // <-- false console.log(`Q: Is ' ' a palindrome? A: ${isPalindrome(' ')}`) // <-- true console.log(`Q: Is 'a' a palindrome? A: ${isPalindrome('a')}`) // <-- true console.log(`Q: Is 'bb' a palindrome? A: ${isPalindrome('bb')}`) // <-- true console.log(`Q: Is 'cdc' a palindrome? A: ${isPalindrome('cdc')}`) // <-- true console.log(`Q: Is 'amanaplanacanalpanama' a palindrome? A: ${isPalindrome('amanaplanacanalpanama')}`) // <-- true -console.log(`Q: Is an integer a palindrome? A: ${isPalindrome(5)}`) // <-- ??? +console.log(`Q: Is an integer a palindrome? A: ${isPalindrome(5)}`) // <-- undefined +// numToStr() test +console.log(numToStr(5)); // <--- '5' +console.log(typeof numToStr(5)); // <--- string +console.log(`Q: Is the integer converted to a string? A: ${isPalindrome(numToStr(5))}`) // <-- true From 7c80e1c67344edc1c0eeb4570278507e040b28e7 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:50:02 -0400 Subject: [PATCH 057/523] add numToStr --- .../findPrimePalindromes.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index d4fd6be..cd758ac 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -3,7 +3,7 @@ const findPrimePals = function(primeArr) { const primePalsArr = [] for (i = 0; i < primeArr.length; i++) { - if (isPalindrome(primeArr[i])) primePalsArr.push(primeArr[i]) + if (isPalindrome(primeArr[i])) primePalsArr.push(numToStr(primeArr[i])) } return primePalsArr; } @@ -37,9 +37,9 @@ const isPrime = function(num) { } return true; } -// I: any string NOTE: handles integers as well √ +// I: any string NOTE: does NOT handle integers // O: "true" if INPUT is a palindrome -const isPalindrome = function(str) { +function isPalindrome(str) { // return true if string is a palindrome. // otherwise return false for (let i = 0; i < str.length / 2; i++) { // <--- make sure divided by 2 handles odd and even length (floor vs. ceiling) @@ -50,13 +50,25 @@ const isPalindrome = function(str) { } } } -// PALINDROME TEST SUITE + +// I: a NUMBER +// O: a STRING +const numToStr = function(num) { + return `${num}`; +} + +// isPalindrome() TEST SUITE console.log(`Q: Is 'palindrome' a palindrome? A: ${isPalindrome('palindrome')}`) // <-- false console.log(`Q: Is ' ' a palindrome? A: ${isPalindrome(' ')}`) // <-- true console.log(`Q: Is 'a' a palindrome? A: ${isPalindrome('a')}`) // <-- true console.log(`Q: Is 'bb' a palindrome? A: ${isPalindrome('bb')}`) // <-- true console.log(`Q: Is 'cdc' a palindrome? A: ${isPalindrome('cdc')}`) // <-- true console.log(`Q: Is 'amanaplanacanalpanama' a palindrome? A: ${isPalindrome('amanaplanacanalpanama')}`) // <-- true +console.log(`Q: Is an integer a palindrome? A: ${isPalindrome(5)}`) // <-- undefined +// numToStr() test +console.log(numToStr(5)); // <--- '5' +console.log(typeof numToStr(5)); // <--- string +console.log(`Q: Is the integer converted to a string? A: ${isPalindrome(numToStr(5))}`) // <-- true // isPrime TEST SUITE // 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, console.log(`Q: Is 0 prime? A: ${isPrime(0)}`) // <--- false From 02184224ad82c902c8798511dc803c51cd23f7c4 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:56:45 -0400 Subject: [PATCH 058/523] =?UTF-8?q?test=20suite=20passes:=20array=20of=20p?= =?UTF-8?q?rime=20palindromes=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../findPrimePalindromes.js | 70 ++++++++++--------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index cd758ac..414c887 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -1,9 +1,10 @@ // I: a sorted array of prime numbers, smallest to largest // O: array of prime palindromes const findPrimePals = function(primeArr) { + console.log(primeArr); const primePalsArr = [] for (i = 0; i < primeArr.length; i++) { - if (isPalindrome(primeArr[i])) primePalsArr.push(numToStr(primeArr[i])) + if (isPalindrome(numToStr(primeArr[i]))) primePalsArr.push(numToStr(primeArr[i])) } return primePalsArr; } @@ -57,41 +58,42 @@ const numToStr = function(num) { return `${num}`; } -// isPalindrome() TEST SUITE -console.log(`Q: Is 'palindrome' a palindrome? A: ${isPalindrome('palindrome')}`) // <-- false -console.log(`Q: Is ' ' a palindrome? A: ${isPalindrome(' ')}`) // <-- true -console.log(`Q: Is 'a' a palindrome? A: ${isPalindrome('a')}`) // <-- true -console.log(`Q: Is 'bb' a palindrome? A: ${isPalindrome('bb')}`) // <-- true -console.log(`Q: Is 'cdc' a palindrome? A: ${isPalindrome('cdc')}`) // <-- true -console.log(`Q: Is 'amanaplanacanalpanama' a palindrome? A: ${isPalindrome('amanaplanacanalpanama')}`) // <-- true -console.log(`Q: Is an integer a palindrome? A: ${isPalindrome(5)}`) // <-- undefined -// numToStr() test -console.log(numToStr(5)); // <--- '5' -console.log(typeof numToStr(5)); // <--- string -console.log(`Q: Is the integer converted to a string? A: ${isPalindrome(numToStr(5))}`) // <-- true -// isPrime TEST SUITE -// 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, -console.log(`Q: Is 0 prime? A: ${isPrime(0)}`) // <--- false -console.log(`Q: Is 1 prime? A: ${isPrime(1)}`) // <--- false -console.log(`Q: Is 2 prime? A: ${isPrime(2)}`) // <--- true -console.log(`Q: Is 3 prime? A: ${isPrime(3)}`) // <--- true -console.log(`Q: Is 4 prime? A: ${isPrime(4)}`) // <--- false -console.log(`Q: Is 5 prime? A: ${isPrime(5)}`) // <--- true -console.log(`Q: Is 6 prime? A: ${isPrime(6)}`) // <--- false -console.log(`Q: Is 7 prime? A: ${isPrime(7)}`) // <--- true -console.log(`Q: Is 8 prime? A: ${isPrime(8)}`) // <--- false -console.log(`Q: Is 9 prime? A: ${isPrime(9)}`) // <--- false -console.log(`Q: Is 10 prime? A: ${isPrime(10)}`) // <--- false -console.log(`Q: Is 11 prime? A: ${isPrime(11)}`) // <--- true -console.log(`Q: Is 12 prime? A: ${isPrime(12)}`) // <--- false -console.log(`Q: Is 13 prime? A: ${isPrime(13)}`) // <--- true -console.log(`Q: Is 121 prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) -console.log(`Q: Is 104729 prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) -// findPrimes TEST SUITE +// // isPalindrome() TEST SUITE +// console.log(`Q: Is 'palindrome' a palindrome? A: ${isPalindrome('palindrome')}`) // <-- false +// console.log(`Q: Is ' ' a palindrome? A: ${isPalindrome(' ')}`) // <-- true +// console.log(`Q: Is 'a' a palindrome? A: ${isPalindrome('a')}`) // <-- true +// console.log(`Q: Is 'bb' a palindrome? A: ${isPalindrome('bb')}`) // <-- true +// console.log(`Q: Is 'cdc' a palindrome? A: ${isPalindrome('cdc')}`) // <-- true +// console.log(`Q: Is 'amanaplanacanalpanama' a palindrome? A: ${isPalindrome('amanaplanacanalpanama')}`) // <-- true +// console.log(`Q: Is an integer a palindrome? A: ${isPalindrome(5)}`) // <-- undefined +// // numToStr() test +// console.log(numToStr(5)); // <--- '5' +// console.log(typeof numToStr(5)); // <--- string +// console.log(`Q: Is the integer converted to a string? A: ${isPalindrome(numToStr(5))}`) // <-- true +// // isPrime TEST SUITE +// // 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, +// console.log(`Q: Is 0 prime? A: ${isPrime(0)}`) // <--- false +// console.log(`Q: Is 1 prime? A: ${isPrime(1)}`) // <--- false +// console.log(`Q: Is 2 prime? A: ${isPrime(2)}`) // <--- true +// console.log(`Q: Is 3 prime? A: ${isPrime(3)}`) // <--- true +// console.log(`Q: Is 4 prime? A: ${isPrime(4)}`) // <--- false +// console.log(`Q: Is 5 prime? A: ${isPrime(5)}`) // <--- true +// console.log(`Q: Is 6 prime? A: ${isPrime(6)}`) // <--- false +// console.log(`Q: Is 7 prime? A: ${isPrime(7)}`) // <--- true +// console.log(`Q: Is 8 prime? A: ${isPrime(8)}`) // <--- false +// console.log(`Q: Is 9 prime? A: ${isPrime(9)}`) // <--- false +// console.log(`Q: Is 10 prime? A: ${isPrime(10)}`) // <--- false +// console.log(`Q: Is 11 prime? A: ${isPrime(11)}`) // <--- true +// console.log(`Q: Is 12 prime? A: ${isPrime(12)}`) // <--- false +// console.log(`Q: Is 13 prime? A: ${isPrime(13)}`) // <--- true +// console.log(`Q: Is 121 prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) +// console.log(`Q: Is 104729 prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) +// // findPrimes TEST SUITE // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127] console.log(`Q: what are the primes from 0 to 127?\nA: ${findPrimes(127)}`); // console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(104729)}`); // <--- 10,000 prime numbers!!!! console.log(findPrimes(104729).length); -// findPrimes TEST SUITE +// findPrimePals TEST SUITE // [11, 101, ...] -console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${findPrimePals(127)}`); +console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${typeof findPrimePals(findPrimes(127))}`); +console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${findPrimePals(findPrimes(127))}`); From 3d2bfd5a99eaedd058ed25f821f874d4c25afb7d Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 12:58:05 -0400 Subject: [PATCH 059/523] added all components --- .../largestPrimePalindrome.js | 108 +++++++++++------- 1 file changed, 67 insertions(+), 41 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index a283909..fa2f42a 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -12,9 +12,24 @@ const largestPrimePalindrome = function(num) { return findPrimePals(findPrimes(num))[-1] // <--- JS doesn't support -1 as array tail :() } +// const findLargestPrime = function(*arrOfPrimes, e.g. findPrimes(###)) { +// return (*arrOfPrimes[*arrOfPrimes - 1]) // <--- last item in array will be largest prime +// } + +// I: a sorted array of prime numbers, smallest to largest +// O: array of prime palindromes +const findPrimePals = function(primeArr) { + console.log(primeArr); + const primePalsArr = [] + for (i = 0; i < primeArr.length; i++) { + if (isPalindrome(numToStr(primeArr[i]))) primePalsArr.push(numToStr(primeArr[i])) + } + return primePalsArr; +} + // evaluates a range of natural numbers // I: largest number in range (inclusive) -// O; an array of ALL prime #'s from range 0 thru input integer +// O: an array of ALL prime #'s from range 0 thru INPUT integer const findPrimes = function(bigNum) { const primes = []; // for number in range 0 thru *num @@ -22,22 +37,10 @@ const findPrimes = function(bigNum) { if (isPrime(i)) primes.push(i); } return primes; -} - -// const findLargestPrime = function(*arrOfPrimes, e.g. findPrimes(###)) { -// return (*arrOfPrimes[*arrOfPrimes - 1]) // <--- last item in array will be largest prime -// } - -// I: a sorted array of prime numbers, smallest to largest -// O: array of prime Palindromes -const findPrimePals = function(*anArrOfPrimes, e.g. findPrimes(###)) { - const primePals = [] - for (i=0;i Date: Fri, 14 Jul 2017 12:59:49 -0400 Subject: [PATCH 060/523] verify --- largestPrimePalindrome/isPrime.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/largestPrimePalindrome/isPrime.js b/largestPrimePalindrome/isPrime.js index 0dc1c00..cab266b 100644 --- a/largestPrimePalindrome/isPrime.js +++ b/largestPrimePalindrome/isPrime.js @@ -1,7 +1,8 @@ -/* return true if num is prime. - otherwise return false */ - +// I: any integer +// O: "true" if INPUT is a prime number const isPrime = function(num) { + // return true if num is prime. + // otherwise return false if (num < 2) {return false;} else if (num === 2) {return true;} else if (num % 2 === 0) {return false;} From 5d885c015a7ccca81d39512e48a8a6e007645beb Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 13:00:44 -0400 Subject: [PATCH 061/523] ibid --- largestPrimePalindrome/isPalindrome.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/largestPrimePalindrome/isPalindrome.js b/largestPrimePalindrome/isPalindrome.js index e1f1780..4d76320 100644 --- a/largestPrimePalindrome/isPalindrome.js +++ b/largestPrimePalindrome/isPalindrome.js @@ -1,3 +1,5 @@ +// I: any string NOTE: does NOT handle integers +// O: "true" if INPUT is a palindrome function isPalindrome(str) { // return true if string is a palindrome. // otherwise return false @@ -10,6 +12,8 @@ function isPalindrome(str) { } } +// I: a NUMBER +// O: a STRING const numToStr = function(num) { return `${num}`; } From 912a457d6b74eba5b371922e83a2b8437ed174fd Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 13:15:25 -0400 Subject: [PATCH 062/523] remove log statement --- largestPrimePalindrome/findPrimePalindromes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index 414c887..ff608cc 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -1,7 +1,7 @@ // I: a sorted array of prime numbers, smallest to largest // O: array of prime palindromes const findPrimePals = function(primeArr) { - console.log(primeArr); + // console.log(primeArr); const primePalsArr = [] for (i = 0; i < primeArr.length; i++) { if (isPalindrome(numToStr(primeArr[i]))) primePalsArr.push(numToStr(primeArr[i])) From 4388133a6060bcfc56c943712c4baafb19d9d966 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 13:15:43 -0400 Subject: [PATCH 063/523] wrestling --- .../largestPrimePalindrome.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index fa2f42a..bdfb4bc 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -9,7 +9,8 @@ // returns largest prime palindrome const largestPrimePalindrome = function(num) { - return findPrimePals(findPrimes(num))[-1] // <--- JS doesn't support -1 as array tail :() + const x = findPrimePals((isPalindrome(numToStr(num)))) // <--- JS doesn't support -1 as array tail :() + return x[x.length - 1]; } // const findLargestPrime = function(*arrOfPrimes, e.g. findPrimes(###)) { @@ -19,7 +20,6 @@ const largestPrimePalindrome = function(num) { // I: a sorted array of prime numbers, smallest to largest // O: array of prime palindromes const findPrimePals = function(primeArr) { - console.log(primeArr); const primePalsArr = [] for (i = 0; i < primeArr.length; i++) { if (isPalindrome(numToStr(primeArr[i]))) primePalsArr.push(numToStr(primeArr[i])) @@ -107,11 +107,12 @@ const numToStr = function(num) { // console.log(`Q: Is 121 prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) // console.log(`Q: Is 104729 prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) // // findPrimes TEST SUITE -// [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127] -console.log(`Q: what are the primes from 0 to 127?\nA: ${findPrimes(127)}`); -// console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(104729)}`); // <--- 10,000 prime numbers!!!! -console.log(findPrimes(104729).length); +// // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127] +// console.log(`Q: what are the primes from 0 to 127?\nA: ${findPrimes(127)}`); +// // console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(104729)}`); // <--- 10,000 prime numbers!!!! +// console.log(findPrimes(104729).length); // findPrimePals TEST SUITE // [11, 101, ...] -console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${typeof findPrimePals(findPrimes(127))}`); -console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${findPrimePals(findPrimes(127))}`); +console.log(`Q: what are the prime palindromes from 0 to 127? A: ${typeof findPrimePals(findPrimes(127))}`); +// console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${findPrimePals(findPrimes(127))}`); +console.log(largestPrimePalindrome(1000)); From 3dc9e478d1bfff64be73fdde88e2caa628ccc203 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 13:23:29 -0400 Subject: [PATCH 064/523] hmm... bringing it all together --- largestPrimePalindrome/largestPrimePalindrome.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index bdfb4bc..e14e23b 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -9,8 +9,8 @@ // returns largest prime palindrome const largestPrimePalindrome = function(num) { - const x = findPrimePals((isPalindrome(numToStr(num)))) // <--- JS doesn't support -1 as array tail :() - return x[x.length - 1]; + const x = findPrimePals((isPalindrome(findPrimes(num)))) // <--- JS doesn't support -1 as array tail :() + return x; } // const findLargestPrime = function(*arrOfPrimes, e.g. findPrimes(###)) { From 329153902479610328441c981f15af48bf99661c Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 14 Jul 2017 13:46:30 -0400 Subject: [PATCH 065/523] ibid --- largestPrimePalindrome/largestPrimePalindrome.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index e14e23b..a919883 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -8,8 +8,10 @@ */ // returns largest prime palindrome +// I: end of range from 0 +// O: largest integer that is both prime and a palindrome const largestPrimePalindrome = function(num) { - const x = findPrimePals((isPalindrome(findPrimes(num)))) // <--- JS doesn't support -1 as array tail :() + const x = findPrimePals(num) return x; } From 1f97ea5f4e6df802cd240d0ff377a0d8afb0d25b Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 00:11:32 -0400 Subject: [PATCH 066/523] =?UTF-8?q?isPrime=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- largestPrimePalindrome/isPrime.js | 34 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/largestPrimePalindrome/isPrime.js b/largestPrimePalindrome/isPrime.js index cab266b..6b96d0d 100644 --- a/largestPrimePalindrome/isPrime.js +++ b/largestPrimePalindrome/isPrime.js @@ -15,21 +15,21 @@ const isPrime = function(num) { } return true; } -// PRIME TEST SUITE +// isPrime TEST SUITE // 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, -console.log(`Q: 0 is prime? A: ${isPrime(0)}`) // <--- false -console.log(`Q: 1 is prime? A: ${isPrime(1)}`) // <--- false -console.log(`Q: 2 is prime? A: ${isPrime(2)}`) // <--- true -console.log(`Q: 3 is prime? A: ${isPrime(3)}`) // <--- true -console.log(`Q: 4 is prime? A: ${isPrime(4)}`) // <--- false -console.log(`Q: 5 is prime? A: ${isPrime(5)}`) // <--- true -console.log(`Q: 6 is prime? A: ${isPrime(6)}`) // <--- false -console.log(`Q: 7 is prime? A: ${isPrime(7)}`) // <--- true -console.log(`Q: 8 is prime? A: ${isPrime(8)}`) // <--- false -console.log(`Q: 9 is prime? A: ${isPrime(9)}`) // <--- false -console.log(`Q: 10 is prime? A: ${isPrime(10)}`) // <--- false -console.log(`Q: 11 is prime? A: ${isPrime(11)}`) // <--- true -console.log(`Q: 12 is prime? A: ${isPrime(12)}`) // <--- false -console.log(`Q: 13 is prime? A: ${isPrime(13)}`) // <--- true -console.log(`Q: 121 is prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) -console.log(`Q: 104729 is prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) +console.log(`Q: Is 0 prime? A: ${isPrime(0)}`) // <--- false +console.log(`Q: Is 1 prime? A: ${isPrime(1)}`) // <--- false +console.log(`Q: Is 2 prime? A: ${isPrime(2)}`) // <--- true +console.log(`Q: Is 3 prime? A: ${isPrime(3)}`) // <--- true +console.log(`Q: Is 4 prime? A: ${isPrime(4)}`) // <--- false +console.log(`Q: Is 5 prime? A: ${isPrime(5)}`) // <--- true +console.log(`Q: Is 6 prime? A: ${isPrime(6)}`) // <--- false +console.log(`Q: Is 7 prime? A: ${isPrime(7)}`) // <--- true +console.log(`Q: Is 8 prime? A: ${isPrime(8)}`) // <--- false +console.log(`Q: Is 9 prime? A: ${isPrime(9)}`) // <--- false +console.log(`Q: Is 10 prime? A: ${isPrime(10)}`) // <--- false +console.log(`Q: Is 11 prime? A: ${isPrime(11)}`) // <--- true +console.log(`Q: Is 12 prime? A: ${isPrime(12)}`) // <--- false +console.log(`Q: Is 13 prime? A: ${isPrime(13)}`) // <--- true +console.log(`Q: Is 121 prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) +console.log(`Q: Is 104729 prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) From e9bda87e64f1f8bb01f8baf7eabbccfd1c4da973 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 00:11:43 -0400 Subject: [PATCH 067/523] =?UTF-8?q?isPalidrome=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- largestPrimePalindrome/isPalindrome.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/largestPrimePalindrome/isPalindrome.js b/largestPrimePalindrome/isPalindrome.js index 4d76320..52ec4c5 100644 --- a/largestPrimePalindrome/isPalindrome.js +++ b/largestPrimePalindrome/isPalindrome.js @@ -27,6 +27,5 @@ console.log(`Q: Is 'cdc' a palindrome? A: ${isPalindrome('cdc' console.log(`Q: Is 'amanaplanacanalpanama' a palindrome? A: ${isPalindrome('amanaplanacanalpanama')}`) // <-- true console.log(`Q: Is an integer a palindrome? A: ${isPalindrome(5)}`) // <-- undefined // numToStr() test -console.log(numToStr(5)); // <--- '5' -console.log(typeof numToStr(5)); // <--- string +console.log(`...might LOOK like a number: ${numToStr(5)} ...but it's a ${typeof numToStr(5)}`) // <--- '5' & string console.log(`Q: Is the integer converted to a string? A: ${isPalindrome(numToStr(5))}`) // <-- true From bfa9bcb25c1d66db065758b98e2a89155fe16953 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 00:11:57 -0400 Subject: [PATCH 068/523] =?UTF-8?q?findPrimes=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- largestPrimePalindrome/findPrimes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/largestPrimePalindrome/findPrimes.js b/largestPrimePalindrome/findPrimes.js index 40a6550..60daad1 100644 --- a/largestPrimePalindrome/findPrimes.js +++ b/largestPrimePalindrome/findPrimes.js @@ -1,9 +1,9 @@ // evaluates a range of natural numbers // I: largest number in range (inclusive) -// O; an array of ALL prime #'s from range 0 thru input integer +// O: an array of ALL prime #'s from range 0 thru input integer const findPrimes = function(bigNum) { const primes = []; - // for number in range 0 thru *num + // for number in range 0 thru bigNum for (i = 0; i <=bigNum; i++) { if (isPrime(i)) primes.push(i); } From 9a3fe0f24e042a7aa1f8efa459fcb4091b620a08 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 00:12:09 -0400 Subject: [PATCH 069/523] =?UTF-8?q?findPrimePalindromes=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- largestPrimePalindrome/findPrimePalindromes.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/largestPrimePalindrome/findPrimePalindromes.js b/largestPrimePalindrome/findPrimePalindromes.js index ff608cc..d7365f6 100644 --- a/largestPrimePalindrome/findPrimePalindromes.js +++ b/largestPrimePalindrome/findPrimePalindromes.js @@ -66,10 +66,12 @@ const numToStr = function(num) { // console.log(`Q: Is 'cdc' a palindrome? A: ${isPalindrome('cdc')}`) // <-- true // console.log(`Q: Is 'amanaplanacanalpanama' a palindrome? A: ${isPalindrome('amanaplanacanalpanama')}`) // <-- true // console.log(`Q: Is an integer a palindrome? A: ${isPalindrome(5)}`) // <-- undefined + // // numToStr() test // console.log(numToStr(5)); // <--- '5' // console.log(typeof numToStr(5)); // <--- string // console.log(`Q: Is the integer converted to a string? A: ${isPalindrome(numToStr(5))}`) // <-- true + // // isPrime TEST SUITE // // 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, // console.log(`Q: Is 0 prime? A: ${isPrime(0)}`) // <--- false @@ -88,12 +90,15 @@ const numToStr = function(num) { // console.log(`Q: Is 13 prime? A: ${isPrime(13)}`) // <--- true // console.log(`Q: Is 121 prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) // console.log(`Q: Is 104729 prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) + // // findPrimes TEST SUITE // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127] console.log(`Q: what are the primes from 0 to 127?\nA: ${findPrimes(127)}`); // console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(104729)}`); // <--- 10,000 prime numbers!!!! console.log(findPrimes(104729).length); + // findPrimePals TEST SUITE // [11, 101, ...] -console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${typeof findPrimePals(findPrimes(127))}`); -console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${findPrimePals(findPrimes(127))}`); +console.log(`Q: Is findPrimePals(findPrimes(127)) an instance of an array?\nA: ${findPrimePals(findPrimes(127)) instanceof Array}`); // <--- true +console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${findPrimePals(findPrimes(127))}`); // <--- 2,3,5,7,11,101 +console.log(`Q: what are the prime palindromes from 0 to 1000?\nA: ${findPrimePals(findPrimes(1000))}`); // <--- 2,3,5,7,11,101,131,151,181,191,313,353,373,383,727,757,787,797,919,929 From 03e6c5f5952bb9a85d314d0ffe73ee3bba568f7f Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 00:12:29 -0400 Subject: [PATCH 070/523] largestPrimePalindrome(1000) = 929 --- .../largestPrimePalindrome.js | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index a919883..6c1766f 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -11,10 +11,11 @@ // I: end of range from 0 // O: largest integer that is both prime and a palindrome const largestPrimePalindrome = function(num) { - const x = findPrimePals(num) - return x; + const x = findPrimePals(findPrimes(num)) + return x[x.length - 1]; } +// THIS MIGHT NEED TO GO // const findLargestPrime = function(*arrOfPrimes, e.g. findPrimes(###)) { // return (*arrOfPrimes[*arrOfPrimes - 1]) // <--- last item in array will be largest prime // } @@ -22,6 +23,7 @@ const largestPrimePalindrome = function(num) { // I: a sorted array of prime numbers, smallest to largest // O: array of prime palindromes const findPrimePals = function(primeArr) { + // console.log(primeArr); const primePalsArr = [] for (i = 0; i < primeArr.length; i++) { if (isPalindrome(numToStr(primeArr[i]))) primePalsArr.push(numToStr(primeArr[i])) @@ -86,10 +88,12 @@ const numToStr = function(num) { // console.log(`Q: Is 'cdc' a palindrome? A: ${isPalindrome('cdc')}`) // <-- true // console.log(`Q: Is 'amanaplanacanalpanama' a palindrome? A: ${isPalindrome('amanaplanacanalpanama')}`) // <-- true // console.log(`Q: Is an integer a palindrome? A: ${isPalindrome(5)}`) // <-- undefined + // // numToStr() test // console.log(numToStr(5)); // <--- '5' // console.log(typeof numToStr(5)); // <--- string // console.log(`Q: Is the integer converted to a string? A: ${isPalindrome(numToStr(5))}`) // <-- true + // // isPrime TEST SUITE // // 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, // console.log(`Q: Is 0 prime? A: ${isPrime(0)}`) // <--- false @@ -108,13 +112,18 @@ const numToStr = function(num) { // console.log(`Q: Is 13 prime? A: ${isPrime(13)}`) // <--- true // console.log(`Q: Is 121 prime? A: ${isPrime(121)}`) // <--- false (11 * 11 = 121) // console.log(`Q: Is 104729 prime? A: ${isPrime(104729)}`)// <--- true (104,729 is the 10,000th prime number!) + // // findPrimes TEST SUITE -// // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127] -// console.log(`Q: what are the primes from 0 to 127?\nA: ${findPrimes(127)}`); -// // console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(104729)}`); // <--- 10,000 prime numbers!!!! -// console.log(findPrimes(104729).length); +// [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127] +console.log(`Q: what are the primes from 0 to 127?\nA: ${findPrimes(127)}`); +// console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(104729)}`); // <--- 10,000 prime numbers!!!! +console.log(findPrimes(104729).length); + // findPrimePals TEST SUITE // [11, 101, ...] -console.log(`Q: what are the prime palindromes from 0 to 127? A: ${typeof findPrimePals(findPrimes(127))}`); -// console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${findPrimePals(findPrimes(127))}`); +console.log(`Q: Is findPrimePals(findPrimes(127)) an instance of an array?\nA: ${findPrimePals(findPrimes(127)) instanceof Array}`); // <--- true +console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${findPrimePals(findPrimes(127))}`); // <--- 2,3,5,7,11,101 +console.log(`Q: what are the prime palindromes from 0 to 1000?\nA: ${findPrimePals(findPrimes(1000))}`); // <--- 2,3,5,7,11,101,131,151,181,191,313,353,373,383,727,757,787,797,919,929 + +// largestPrimePalindrome TEST SUITE console.log(largestPrimePalindrome(1000)); From f04e7bfc81e4ef2574b61f11e8262a0b9f66e53b Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 00:18:00 -0400 Subject: [PATCH 071/523] =?UTF-8?q?all=20test=20suites=20pass=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- largestPrimePalindrome/largestPrimePalindrome.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 6c1766f..0e20781 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -15,11 +15,6 @@ const largestPrimePalindrome = function(num) { return x[x.length - 1]; } -// THIS MIGHT NEED TO GO -// const findLargestPrime = function(*arrOfPrimes, e.g. findPrimes(###)) { -// return (*arrOfPrimes[*arrOfPrimes - 1]) // <--- last item in array will be largest prime -// } - // I: a sorted array of prime numbers, smallest to largest // O: array of prime palindromes const findPrimePals = function(primeArr) { From 3322a03f1f60332d4390f911a25a1d8935977ade Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 00:24:05 -0400 Subject: [PATCH 072/523] test suite improvements (i swear I am done for now!) --- .../largestPrimePalindrome.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 0e20781..3be3be9 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -110,15 +110,15 @@ const numToStr = function(num) { // // findPrimes TEST SUITE // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127] -console.log(`Q: what are the primes from 0 to 127?\nA: ${findPrimes(127)}`); -// console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(104729)}`); // <--- 10,000 prime numbers!!!! -console.log(findPrimes(104729).length); +// console.log(`Q: what are the primes from 0 to 127?\nA: ${findPrimes(127)}`); +// // console.log(`Q: what are the primes from 0 to 121?\nA: ${findPrimes(104729)}`); // <--- 10,000 prime numbers!!!! +// console.log(`Q: How many prime numbers between zero and 104,729?\nA: ${findPrimes(104729).length}`); -// findPrimePals TEST SUITE -// [11, 101, ...] -console.log(`Q: Is findPrimePals(findPrimes(127)) an instance of an array?\nA: ${findPrimePals(findPrimes(127)) instanceof Array}`); // <--- true -console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${findPrimePals(findPrimes(127))}`); // <--- 2,3,5,7,11,101 -console.log(`Q: what are the prime palindromes from 0 to 1000?\nA: ${findPrimePals(findPrimes(1000))}`); // <--- 2,3,5,7,11,101,131,151,181,191,313,353,373,383,727,757,787,797,919,929 +// // findPrimePals TEST SUITE +// // [11, 101, ...] +// console.log(`Q: Is findPrimePals(findPrimes(127)) an instance of an array?\nA: ${findPrimePals(findPrimes(127)) instanceof Array}`); // <--- true +// console.log(`Q: what are the prime palindromes from 0 to 127?\nA: ${findPrimePals(findPrimes(127))}`); // <--- 2,3,5,7,11,101 +// console.log(`Q: what are the prime palindromes from 0 to 1000?\nA: ${findPrimePals(findPrimes(1000))}`); // <--- 2,3,5,7,11,101,131,151,181,191,313,353,373,383,727,757,787,797,919,929 // largestPrimePalindrome TEST SUITE -console.log(largestPrimePalindrome(1000)); +console.log(`Q: What is the largest prime palindrome less than 1000?\nA: ${largestPrimePalindrome(1000)}`); From 8d4571afe268471ef070ce56d45b87641bffd81f Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 13:47:24 -0400 Subject: [PATCH 073/523] RH's solution from the lecture viddy --- largestPrimePalindrome/ryan_solution.js | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 largestPrimePalindrome/ryan_solution.js diff --git a/largestPrimePalindrome/ryan_solution.js b/largestPrimePalindrome/ryan_solution.js new file mode 100644 index 0000000..786d8a5 --- /dev/null +++ b/largestPrimePalindrome/ryan_solution.js @@ -0,0 +1,27 @@ +// from the lecture video: https://youtu.be/F0y2sJHQzzs +const largestPrimePalindrome = (number) => { + + const palindromeChecker = (number) => { + const strNum = number.toString(); + const reversedStrNum = strNum.split('').reverse().join(''); + if (strNum == reversedStrNum) return true; // <--- NOTE THE USE OF "==" (NOT "==="): COERCION + // if (strNum === Number(reversedStrNum)) return true; + return false; + }; + + const primeChecker = (num) => { + const squareRoot = Math.sqrt(num); + if (num % 2 === 0) return false; + for(let i = 3; i <= squareRoot; i += 2) { + if (num % i === 0) return false; + } + return true; + }; + + // COUNTING DOWN FROM LARGEST IS MUCH MUCH MUCH FASTER + for (let num = 1000; num >= 11; num--) + if( palindromeChecker(num) && primeChecker(num) ) return num; + +}; + +console.log(largestPrimePalindrome()); From 8399689557c8deed2af01d8b8b002de7e719dd04 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 13:48:30 -0400 Subject: [PATCH 074/523] =?UTF-8?q?ERR=20-=20previous=20version=20ONLY=20f?= =?UTF-8?q?ound=20dupes=20of=20index[0]:=20now=20OK=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- isUnique/isUnique.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/isUnique/isUnique.js b/isUnique/isUnique.js index 18dd90a..c284dd2 100755 --- a/isUnique/isUnique.js +++ b/isUnique/isUnique.js @@ -4,10 +4,19 @@ */ const isUnique = (str) => { - for (let i = 1; i < str.length; i++) { - if (str[0] === str[i]) return false; - } return true; + for (let i = 0; i < str.length; i++) { + for (let j = i + 1; j < str.length; j++) { + // console.log(`Q: does ${str[i]} === ${str[j]}? A: ${str[i] === str[j]}`) + if (str[i] === str[j]) { + return false; + } + } + } return true; }; console.log(isUnique('abcdhijklmnopqrstuv')); // true +console.log(isUnique('abcdefghijklmnopqrstuvwyz')); // true console.log(isUnique('abcdefga')); // false +console.log(isUnique('bcdgefga')); // false +console.log(isUnique([1, 2, 3, 4, 5, 6, 3])); // false +console.log(isUnique([0, 1, 2, 3, 4, 6, 7, 8, 9, 9])); // false From c945e6952a591dbfff19899b3b222819eb1a8a09 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 13:48:53 -0400 Subject: [PATCH 075/523] rough sketch --- evenOccurences/evenOccurences.js | 51 +++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index 35da569..ae48fda 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -1,15 +1,44 @@ /* - * * Find the first item that occurs an even number of times in an array. - * * Remember to handle multiple even-occurance items and return the first one. - * * Return null if there are no even-occurance items. - * */ - -/* - * * example usage: - * * const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); - * * console.log(onlyEven); // 4 - * */ +* Find the first item that occurs an even number of times in an array. + * Remember to handle multiple even-occurance items and return the first one. + * Return null if there are no even-occurance items. +* example usage: + * const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); + * console.log(onlyEven); // 4 + */ +// I: array +// F(): isUnique false return, then check total number of times +// item is in array, %2 === 0 dun, or check next until null +// O: array item - first instance of item which occurs even # of times in array const evenOccurence = (arr) => { - // Your code here. + + const isUnique = (str) => { + for (let i = 0; i < str.length; i++) { + for (let j = i + 1; j < str.length; j++) { + // console.log(`Q: does ${str[i]} === ${str[j]}? A: ${str[i] === str[j]}`) + if (str[i] === str[j]) { + return false; + } + } + } return true; + }; + // isUnique TEST SUITE: + console.log(isUnique('abcdhijklmnopqrstuv')); // true + console.log(isUnique('abcdefghijklmnopqrstuvwyz')); // true + console.log(isUnique('abcdefga')); // false + console.log(isUnique('bcdgefga')); // false + console.log(isUnique([1, 2, 3, 4, 5, 6, 3])); // false + console.log(isUnique([0, 1, 2, 3, 4, 6, 7, 8, 9, 9])); // false + + + const notUnique = () => { + + } + + // return isUnique(arr) + }; + +evenOccurence(); +// console.log(evenOccurence([1, 2, 3, 4, 5, 6, 3])); From 7e29a739d9567bf15106975e08566fadd9f3c1bb Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 17:49:47 -0400 Subject: [PATCH 076/523] =?UTF-8?q?countNotUnique=20passes=20test=20suite?= =?UTF-8?q?=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- evenOccurences/evenOccurences.js | 49 +++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index ae48fda..9211ae9 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -13,30 +13,47 @@ // O: array item - first instance of item which occurs even # of times in array const evenOccurence = (arr) => { - const isUnique = (str) => { + // I: array + // O: if (isUnique(array)) ? uniqueArrayItem : null + const isUnique = (str) => { // <----- works fine for arrays for (let i = 0; i < str.length; i++) { for (let j = i + 1; j < str.length; j++) { // console.log(`Q: does ${str[i]} === ${str[j]}? A: ${str[i] === str[j]}`) if (str[i] === str[j]) { - return false; + return str[i]; } } - } return true; + } return null; }; - // isUnique TEST SUITE: - console.log(isUnique('abcdhijklmnopqrstuv')); // true - console.log(isUnique('abcdefghijklmnopqrstuvwyz')); // true - console.log(isUnique('abcdefga')); // false - console.log(isUnique('bcdgefga')); // false - console.log(isUnique([1, 2, 3, 4, 5, 6, 3])); // false - console.log(isUnique([0, 1, 2, 3, 4, 6, 7, 8, 9, 9])); // false - - - const notUnique = () => { - +// // isUnique TEST SUITE: +// console.log(isUnique('abcdhijklmnopqrstuv')); // true +// console.log(isUnique('abcdefghijklmnopqrstuvwyz')); // true +// console.log(isUnique('abcdefga')); // false +// console.log(isUnique('bcdgefga')); // false +// console.log(isUnique([1, 2, 3, 4, 5, 6, 3])); // false +// console.log(isUnique([0, 1, 2, 3, 4, 6, 7, 8, 9, 9])); // false + + // I: array + // O: 1st item that occurs an even number of times in an array + const countNotUnique = (item, anArrayOfItems) => { + const hold = []; + if (!isUnique(item)) { + for (let i = 0; i < anArrayOfItems.length; i++) { + if (anArrayOfItems[i] === item) { + hold.push(item); + } + } + } + const count = hold.length; + if ((count === 0) || (count % 2 !== 0)) { + console.log(`no dupes || odd # of dupes`); + } + console.log(`${anArrayOfItems} has ${count} many instances of ${item}: ${hold}`) } - - // return isUnique(arr) +// countNotUnique TEST SUITE: +countNotUnique(1, [5, 1, 1, 1, 1]); // <---------------------- 4 instances of 1 +countNotUnique(1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // <--- no dupes >>> null +countNotUnique(1, [5, 1, 1, 1, 6]); // <---------------------- odd dupes >> null }; From 060b7809569e122146f7e2cdb7b805c9b6bb7390 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 19:05:32 -0400 Subject: [PATCH 077/523] Maybe a better way than this: return oddOrEven(countNotUnique(isUnique(arr), arr)); --- evenOccurences/evenOccurences.js | 56 ++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index 9211ae9..80a9bc1 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -8,34 +8,32 @@ */ // I: array -// F(): isUnique false return, then check total number of times +// F(): if isUnique is false, then return null, then check total number of times // item is in array, %2 === 0 dun, or check next until null // O: array item - first instance of item which occurs even # of times in array const evenOccurence = (arr) => { // I: array - // O: if (isUnique(array)) ? uniqueArrayItem : null - const isUnique = (str) => { // <----- works fine for arrays - for (let i = 0; i < str.length; i++) { - for (let j = i + 1; j < str.length; j++) { - // console.log(`Q: does ${str[i]} === ${str[j]}? A: ${str[i] === str[j]}`) - if (str[i] === str[j]) { - return str[i]; + // O: if (isUnique(anArray)) ? 1st unique array item : null + const isUnique = (anArray) => { + if (anArray === null) /* console.log(`That's some kinda ${anArray} isUnique array there`); */ return null; + // console.log(anArray); + // console.log(`${anArray} ...next stop is the for loop:`); + for (let i = 0; i < anArray.length; i++) { + for (let j = i + 1; j < anArray.length; j++) { + // console.log(`Q: does ${anArray[i]} === ${anArray[j]}? A: ${anArray[i] === anArray[j]}`) + if (anArray[i] === anArray[j]) { + return anArray[i]; } } } return null; }; -// // isUnique TEST SUITE: -// console.log(isUnique('abcdhijklmnopqrstuv')); // true -// console.log(isUnique('abcdefghijklmnopqrstuvwyz')); // true -// console.log(isUnique('abcdefga')); // false -// console.log(isUnique('bcdgefga')); // false -// console.log(isUnique([1, 2, 3, 4, 5, 6, 3])); // false -// console.log(isUnique([0, 1, 2, 3, 4, 6, 7, 8, 9, 9])); // false // I: array // O: 1st item that occurs an even number of times in an array const countNotUnique = (item, anArrayOfItems) => { + if (item === null) /* console.log(`That's some kinda ${item} item`); */ return null; + if (anArrayOfItems === null) console.log(`That's some kinda ${anArrayOfItems} anArrayOfItems array there`); // return null; const hold = []; if (!isUnique(item)) { for (let i = 0; i < anArrayOfItems.length; i++) { @@ -44,18 +42,28 @@ const evenOccurence = (arr) => { } } } - const count = hold.length; + return hold; + } + + const oddOrEven = (dupesArray) => { + if (dupesArray === null) /* console.log(`That's some kinda ${dupesArray} oddOrEven array`); */ return null; + const count = dupesArray.length; if ((count === 0) || (count % 2 !== 0)) { - console.log(`no dupes || odd # of dupes`); + /* console.log(`no dupes || odd # of dupes`); */return null; } - console.log(`${anArrayOfItems} has ${count} many instances of ${item}: ${hold}`) + console.log(`The holding array for duplicates has ${count} instances of ${dupesArray[0]}: ${dupesArray}`) + return dupesArray[0] } -// countNotUnique TEST SUITE: -countNotUnique(1, [5, 1, 1, 1, 1]); // <---------------------- 4 instances of 1 -countNotUnique(1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // <--- no dupes >>> null -countNotUnique(1, [5, 1, 1, 1, 6]); // <---------------------- odd dupes >> null + + return oddOrEven(countNotUnique(isUnique(arr), arr)); }; -evenOccurence(); -// console.log(evenOccurence([1, 2, 3, 4, 5, 6, 3])); +// evenOccurence TEST SUITE: +// evenOccurence(); +console.log(`Invoking evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])}: ${evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])}`); +evenOccurence([5, 1, 1, 1, 1]); // <------------------------ 1 x4 >>> 1 +evenOccurence([1, 2, 3]) // <------------------------------- null +evenOccurence([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // <----- null +evenOccurence([5, 1, 1, 1, 6]); // <--------------- 1 x3 >>> null +evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); // <--- 4 x2 >>> 4 From e298ec1d1f99f599131c64b353d1b10f1215e775 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 19:08:36 -0400 Subject: [PATCH 078/523] =?UTF-8?q?extra=20credit=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- largestPrimePalindrome/largestPrimePalindrome.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 3be3be9..b4fd5d1 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -122,3 +122,5 @@ const numToStr = function(num) { // largestPrimePalindrome TEST SUITE console.log(`Q: What is the largest prime palindrome less than 1000?\nA: ${largestPrimePalindrome(1000)}`); + +// THIS COULD< OF COURSE< BE SIGNIFICANTLY REFACTORED... From 1af66a6f5c12f504954eaa01f3ce30e6106b8f9c Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 19:17:46 -0400 Subject: [PATCH 079/523] Formatting changes for GitHub's markdown layout (ctrl+shift+m for preview in Atom) --- readme.md | 83 ++++++------------------------------------------------- 1 file changed, 8 insertions(+), 75 deletions(-) diff --git a/readme.md b/readme.md index c59c286..347418c 100644 --- a/readme.md +++ b/readme.md @@ -1,76 +1,9 @@ # CS1 - Lambda School Code Challenges -## steps to ensuring your changes get pulled down -1. You will only need to run this step once -```console -git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git -``` - -## NOTE: I think this step is incorrect -2. To get the changes to the repo each day run this -```console -git pull upstream master -``` - -3. You'll then have to resolve any merge conflicts that come up. Don't worry, you'll be pros at this after you're done and this is something that you'll have to do in the real world... all the time. :/ - -*** - -# NOTE TO RYAN from Patrick: - -1. After the origin and upstream are established, such that: -```console -$ git remote -v -origin https://github.com/ryanhca/CS1-Code-Challenges.git (fetch) -origin https://github.com/ryanhca/CS1-Code-Challenges.git (push) -upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges (fetch) -upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges (push) -``` - -2. Then, to get the changes from the origin (ryanhca) master, the students will need to run: -```console -$ git pull origin master -``` - -3. These commands posted durig the Brown Bag -```console -git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git -git pull upstream master -git remote -v - -git remote set-url upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges -// git push/commit etc. -``` - -4. ...should be changed to: -```console -// THESE TWO STEPS ONLY NEED TO BE DONE ONCE -$ git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git -$ git pull upstream master - -// USE THIS TO SEE HOW YOUR ORIGIN AND UPSTREAM ARE CONFIGURED FOR FETCH AND PUSH -$ git remote -v - -// SET YOUR UPSTREAM TO YOUR GITHUB -$ git remote set-url upstream https://github.com/-STUDENT_GITHUB_HANDLE-/CS1-Code-Challenges - -// CONFIRM THAT ORIGIN IS RYAN AND UPSTREAM IS YOUR GITHUB ACCOUNT -$ git remote -v - -// NOW, FOR EACH NEW CODING CHALLENGE -// TO GET NEW CONTENT: -$ git pull origin master -// May require merge conflict resolution - -// STAGING FILES LOCALLY -$ git add -// MAKING LOCAL COMMITS -$ git commit -m '' -// STAYS THE SAME. - -// TO PUSH YOUR WORK TO YOUR GITHUB REPOSITORY: -$ git push upstream master - -// TO SUBMIT A PULL REQUEST TO RYAN'S (origin) GITHUB REPOSITORY, -// GO ONLINE TO https://github.com/ryanhca/CS1-Code-Challenges -// RYAN'S REPOSITORY AND SUBMIT A NEW PULL REQUEST -``` +## Steps to ensuring your changes get pulled down: +1. **You will only need to run this step once:** + - `git remote add upstream https://github.com/ryanhca/CS1-Code-Challenges.git` +2. **To get the daily repo changes each day, run this:** + - `git pull upstream master` + +### You'll then have to resolve any merge conflicts that come up. +*(Don't worry, you'll be pros at this after you're done and this is something that you'll have to do in the real world... all the time)* From 876a2fb59e1d777033d52350f42eb1f6b0b05ed1 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 19:23:27 -0400 Subject: [PATCH 080/523] =?UTF-8?q?longestString=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- longestString/solution.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/longestString/solution.js b/longestString/solution.js index 8cc3d33..87fa3c2 100644 --- a/longestString/solution.js +++ b/longestString/solution.js @@ -1,3 +1,15 @@ +const longestString = (strArr) => { + let tempStr = ''; + strArr.forEach(str => { + if(str.length > tempStr.length) tempStr = str; + }); + return tempStr; +}; + +longestString(['abc', 'def', 'gasdfasf', 'asdf', 'e', 'agwoaiengpoing']); + +// Ryan's lecture video comments: +// https://youtu.be/juZvUpn4j5Y const longestString = (strArr) => { // tempStr variable to hold the string let tempStr = ''; From e1ea191dff3433b78ad8870dfda0ab870d3473c2 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 20:06:15 -0400 Subject: [PATCH 081/523] =?UTF-8?q?evenOccurrences=20done=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- evenOccurences/evenOccurences.js | 37 ++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index 80a9bc1..f9639dc 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -12,6 +12,8 @@ // item is in array, %2 === 0 dun, or check next until null // O: array item - first instance of item which occurs even # of times in array const evenOccurence = (arr) => { + arr; + // console.log(arr); // I: array // O: if (isUnique(anArray)) ? 1st unique array item : null @@ -46,13 +48,26 @@ const evenOccurence = (arr) => { } const oddOrEven = (dupesArray) => { + const minusOddDupe = []; if (dupesArray === null) /* console.log(`That's some kinda ${dupesArray} oddOrEven array`); */ return null; const count = dupesArray.length; - if ((count === 0) || (count % 2 !== 0)) { + // console.log(count); + if (count === 0) { /* console.log(`no dupes || odd # of dupes`); */return null; + } else if (count % 2 !== 0) { + // console.log(`that's odd: ${arr}`) + for (let i = 0; i < arr.length; i++) { + // console.log(`if ${dupesArray[0]} !== ${arr[i]}`); + if (dupesArray[0] !== arr[i]) { + minusOddDupe.push(arr[i]); + } + // console.log(`minus dupes? ${minusOddDupe}`); + } + return evenOccurence(minusOddDupe); } - console.log(`The holding array for duplicates has ${count} instances of ${dupesArray[0]}: ${dupesArray}`) - return dupesArray[0] + // console.log(`The holding array for duplicates has ${count} instances of ${dupesArray[0]}: ${dupesArray}`) + return dupesArray[0]; + // return dupesArray.length; } return oddOrEven(countNotUnique(isUnique(arr), arr)); @@ -61,9 +76,13 @@ const evenOccurence = (arr) => { // evenOccurence TEST SUITE: // evenOccurence(); -console.log(`Invoking evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])}: ${evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])}`); -evenOccurence([5, 1, 1, 1, 1]); // <------------------------ 1 x4 >>> 1 -evenOccurence([1, 2, 3]) // <------------------------------- null -evenOccurence([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // <----- null -evenOccurence([5, 1, 1, 1, 6]); // <--------------- 1 x3 >>> null -evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); // <--- 4 x2 >>> 4 +// console.log(`Invoking evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])} returns the repeated integer: ${evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])}`); +// evenOccurence([5, 1, 1, 1, 1]); // <------------------------ 1 x4 >>> 1 +// evenOccurence([1, 2, 3]) // <------------------------------- null +// evenOccurence([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // <----- null +// evenOccurence([5, 1, 1, 1, 6, 1, 1]); // <--------- 1 x5 >>> null +// evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); // <--- 4 x2 >>> 4 + + +const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); +console.log(onlyEven); From 3c4be3faa4f0a31c883bf4b29b85e48807289696 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 21:32:06 -0400 Subject: [PATCH 082/523] version 1 comsoles removed --- evenOccurences/evenOccurences.js | 36 +++++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index f9639dc..3940e23 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -7,23 +7,37 @@ * console.log(onlyEven); // 4 */ +// // version 2 √ +// const evenOccurence = (arr) => { +// const unique = [...new Set(arr)]; // <---------- Will Set maintain list order????? +// let count = 0; +// for (i in unique) { +// count = 0; +// for (j in arr) { +// if (unique[i] === arr[j]) { +// count++; +// } +// } +// // if (count % 2 === 0) console.log(`${unique[i]} occurs ${count} times.`); +// if (count % 2 === 0) return unique[i]; // <--- how to write this as a ternary operator? +// // return (count % 2 === 0) ? unique[i] : null; +// } +// }; + +// VERSION 1 √ // I: array // F(): if isUnique is false, then return null, then check total number of times // item is in array, %2 === 0 dun, or check next until null // O: array item - first instance of item which occurs even # of times in array const evenOccurence = (arr) => { arr; - // console.log(arr); // I: array // O: if (isUnique(anArray)) ? 1st unique array item : null const isUnique = (anArray) => { - if (anArray === null) /* console.log(`That's some kinda ${anArray} isUnique array there`); */ return null; - // console.log(anArray); - // console.log(`${anArray} ...next stop is the for loop:`); + if (anArray === null) return null; for (let i = 0; i < anArray.length; i++) { for (let j = i + 1; j < anArray.length; j++) { - // console.log(`Q: does ${anArray[i]} === ${anArray[j]}? A: ${anArray[i] === anArray[j]}`) if (anArray[i] === anArray[j]) { return anArray[i]; } @@ -49,29 +63,22 @@ const evenOccurence = (arr) => { const oddOrEven = (dupesArray) => { const minusOddDupe = []; - if (dupesArray === null) /* console.log(`That's some kinda ${dupesArray} oddOrEven array`); */ return null; + if (dupesArray === null) return null; const count = dupesArray.length; - // console.log(count); if (count === 0) { - /* console.log(`no dupes || odd # of dupes`); */return null; + return null; } else if (count % 2 !== 0) { - // console.log(`that's odd: ${arr}`) for (let i = 0; i < arr.length; i++) { - // console.log(`if ${dupesArray[0]} !== ${arr[i]}`); if (dupesArray[0] !== arr[i]) { minusOddDupe.push(arr[i]); } - // console.log(`minus dupes? ${minusOddDupe}`); } return evenOccurence(minusOddDupe); } - // console.log(`The holding array for duplicates has ${count} instances of ${dupesArray[0]}: ${dupesArray}`) return dupesArray[0]; - // return dupesArray.length; } return oddOrEven(countNotUnique(isUnique(arr), arr)); - }; // evenOccurence TEST SUITE: @@ -83,6 +90,5 @@ const evenOccurence = (arr) => { // evenOccurence([5, 1, 1, 1, 6, 1, 1]); // <--------- 1 x5 >>> null // evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); // <--- 4 x2 >>> 4 - const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); console.log(onlyEven); From 6199a06aba40e0155e3f7cfa08b5b1f9b7893e90 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 21:37:27 -0400 Subject: [PATCH 083/523] =?UTF-8?q?version=202=20=E2=88=9A=20(Set,=20sprea?= =?UTF-8?q?d=20op.,=20for=20(in))?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- evenOccurences/evenOccurences.js | 151 +++++++++++++++---------------- 1 file changed, 75 insertions(+), 76 deletions(-) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index 3940e23..266aa78 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -7,88 +7,87 @@ * console.log(onlyEven); // 4 */ -// // version 2 √ -// const evenOccurence = (arr) => { -// const unique = [...new Set(arr)]; // <---------- Will Set maintain list order????? -// let count = 0; -// for (i in unique) { -// count = 0; -// for (j in arr) { -// if (unique[i] === arr[j]) { -// count++; -// } -// } -// // if (count % 2 === 0) console.log(`${unique[i]} occurs ${count} times.`); -// if (count % 2 === 0) return unique[i]; // <--- how to write this as a ternary operator? -// // return (count % 2 === 0) ? unique[i] : null; -// } -// }; - -// VERSION 1 √ -// I: array -// F(): if isUnique is false, then return null, then check total number of times -// item is in array, %2 === 0 dun, or check next until null -// O: array item - first instance of item which occurs even # of times in array +// VERSION 2 √ ...from 50+ lines of code to 13 :) const evenOccurence = (arr) => { - arr; - - // I: array - // O: if (isUnique(anArray)) ? 1st unique array item : null - const isUnique = (anArray) => { - if (anArray === null) return null; - for (let i = 0; i < anArray.length; i++) { - for (let j = i + 1; j < anArray.length; j++) { - if (anArray[i] === anArray[j]) { - return anArray[i]; - } - } - } return null; - }; - - // I: array - // O: 1st item that occurs an even number of times in an array - const countNotUnique = (item, anArrayOfItems) => { - if (item === null) /* console.log(`That's some kinda ${item} item`); */ return null; - if (anArrayOfItems === null) console.log(`That's some kinda ${anArrayOfItems} anArrayOfItems array there`); // return null; - const hold = []; - if (!isUnique(item)) { - for (let i = 0; i < anArrayOfItems.length; i++) { - if (anArrayOfItems[i] === item) { - hold.push(item); - } + const unique = [...new Set(arr)]; // <---------- Will Set maintain list order????? Also, still not used to spread operator. + let count = 0; + for (i in unique) { + count = 0; + for (j in arr) { + if (unique[i] === arr[j]) { + count++; } } - return hold; + if (count % 2 === 0) return unique[i]; // <--- how to write this as a ternary operator? + // return (count % 2 === 0) ? unique[i] : null; } - - const oddOrEven = (dupesArray) => { - const minusOddDupe = []; - if (dupesArray === null) return null; - const count = dupesArray.length; - if (count === 0) { - return null; - } else if (count % 2 !== 0) { - for (let i = 0; i < arr.length; i++) { - if (dupesArray[0] !== arr[i]) { - minusOddDupe.push(arr[i]); - } - } - return evenOccurence(minusOddDupe); - } - return dupesArray[0]; - } - - return oddOrEven(countNotUnique(isUnique(arr), arr)); }; -// evenOccurence TEST SUITE: -// evenOccurence(); -// console.log(`Invoking evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])} returns the repeated integer: ${evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])}`); -// evenOccurence([5, 1, 1, 1, 1]); // <------------------------ 1 x4 >>> 1 -// evenOccurence([1, 2, 3]) // <------------------------------- null -// evenOccurence([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // <----- null -// evenOccurence([5, 1, 1, 1, 6, 1, 1]); // <--------- 1 x5 >>> null -// evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); // <--- 4 x2 >>> 4 +// // VERSION 1 √ +// // I: array +// // F(): if isUnique is false, then return null, then check total number of times +// // item is in array, %2 === 0 dun, or check next until null +// // O: array item - first instance of item which occurs even # of times in array +// const evenOccurence = (arr) => { +// arr; +// +// // I: array +// // O: if (isUnique(anArray)) ? 1st unique array item : null +// const isUnique = (anArray) => { +// if (anArray === null) return null; +// for (let i = 0; i < anArray.length; i++) { +// for (let j = i + 1; j < anArray.length; j++) { +// if (anArray[i] === anArray[j]) { +// return anArray[i]; +// } +// } +// } return null; +// }; +// +// // I: array +// // O: 1st item that occurs an even number of times in an array +// const countNotUnique = (item, anArrayOfItems) => { +// if (item === null) /* console.log(`That's some kinda ${item} item`); */ return null; +// if (anArrayOfItems === null) console.log(`That's some kinda ${anArrayOfItems} anArrayOfItems array there`); // return null; +// const hold = []; +// if (!isUnique(item)) { +// for (let i = 0; i < anArrayOfItems.length; i++) { +// if (anArrayOfItems[i] === item) { +// hold.push(item); +// } +// } +// } +// return hold; +// } +// +// const oddOrEven = (dupesArray) => { +// const minusOddDupe = []; +// if (dupesArray === null) return null; +// const count = dupesArray.length; +// if (count === 0) { +// return null; +// } else if (count % 2 !== 0) { +// for (let i = 0; i < arr.length; i++) { +// if (dupesArray[0] !== arr[i]) { +// minusOddDupe.push(arr[i]); +// } +// } +// return evenOccurence(minusOddDupe); <--------- LOOK MA, RECURSION!!!!! +// } +// return dupesArray[0]; +// } +// +// return oddOrEven(countNotUnique(isUnique(arr), arr)); +// }; +// +// // evenOccurence TEST SUITE: +// // evenOccurence(); +// // console.log(`Invoking evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])} returns the repeated integer: ${evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])}`); +// // evenOccurence([5, 1, 1, 1, 1]); // <------------------------ 1 x4 >>> 1 +// // evenOccurence([1, 2, 3]) // <------------------------------- null +// // evenOccurence([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // <----- null +// // evenOccurence([5, 1, 1, 1, 6, 1, 1]); // <--------- 1 x5 >>> null +// // evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); // <--- 4 x2 >>> 4 const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); console.log(onlyEven); From a776cb982a22ef0cb959b1287e487edf3a6bf924 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 15 Jul 2017 21:43:30 -0400 Subject: [PATCH 084/523] =?UTF-8?q?version=202=20evenOccurences=20?= =?UTF-8?q?=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- evenOccurences/evenOccurences.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index 266aa78..8e864e5 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -18,9 +18,9 @@ const evenOccurence = (arr) => { count++; } } - if (count % 2 === 0) return unique[i]; // <--- how to write this as a ternary operator? - // return (count % 2 === 0) ? unique[i] : null; + if (count % 2 === 0) return unique[i]; } + return null; }; // // VERSION 1 √ @@ -90,4 +90,8 @@ const evenOccurence = (arr) => { // // evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); // <--- 4 x2 >>> 4 const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); -console.log(onlyEven); +console.log(onlyEven); // <--- 4 +const onlyEven2 = evenOccurence([ 1, 7, 2, 4, 5, 6, 8, 9 ]); +console.log(onlyEven2); // <--- null +const onlyEven3 = evenOccurence([ 1, 3, 3, 3, 5, 5, 5, 5, 5 ]); +console.log(onlyEven3); // <--- null From 54a32bf3082c698b114ade68ed494a5830e972fd Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 17 Jul 2017 12:47:23 -0400 Subject: [PATCH 085/523] =?UTF-8?q?CC=206=20callbackPractice=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- callbackPractice/callbackPractice.js | 45 +++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/callbackPractice/callbackPractice.js b/callbackPractice/callbackPractice.js index 931c19d..2844d8a 100644 --- a/callbackPractice/callbackPractice.js +++ b/callbackPractice/callbackPractice.js @@ -17,6 +17,20 @@ // Write a function called firstItem that passes the first item of the given array to the callback function +// version 1 √ +const firstItem = (array, cb) => { + cb(array[0]) +} + +// // version 2 √ +// const firstItem = (array, cb) => { +// x = array.shift(); // <--- degrades the array +// console.log(x); +// } +// version 3 √ +// const firstItem = (array, cb) => { +// console.log(array.shift()); // <--- degrades the array +// } const foods = ['pineapple', 'mango', 'ribeye', 'curry', 'tacos', 'ribeye', 'mango']; @@ -25,25 +39,40 @@ firstItem(foods, (firstItem) => { }); // Write a function called getLength that passes the length of the array into the callback +// version 1 √ +const getLength = (anArray, cb) => { + cb(anArray.length); +} getLength(foods, (length) => { console.log(`The length of the array is ${length}.`); }); // Write a function called last which passes the last item of the array into the callback +// version 1 √ +const last = (theArray, cb) => { + cb(theArray[theArray.length - 1]) +} last(foods, (lastItem) => { console.log(`The last item in the array is ${lastItem}.`); }); // Write a function called sumNums that adds two numbers and passes the result to the callback - +// version 1 √ +const sumNums = (x, y, cb) => { + cb(x + y); +} sumNums(5, 10, (sum) => { console.log(`The sum is ${sum}.`); }); // Write a function called multiplyNums that adds two numbers and passes the result to the callback +// version 1 √ +const multiplyNums = (x, y, cb) => { + cb( x * y); +} multiplyNums(5, 10, (product) => { console.log(`The product is ${product}.`); @@ -51,6 +80,10 @@ multiplyNums(5, 10, (product) => { // Write a function called contains that checks if an item is present inside of the given array. // Pass true to the callback if it is, otherwise pass false +// version 1 √ +const contains = (array, str, cb) => { + cb(array.includes(str)); +} contains(foods, 'ribeye', (result) => { console.log(result ? 'ribeye is in the array' : 'ribeye is not in the array'); @@ -58,12 +91,22 @@ contains(foods, 'ribeye', (result) => { // Write a function called removeDuplicates that removes all duplicate values from the given array. // Pass the array to the callback function. Do not mutate the original array. +// version 1 √ +const removeDuplicates = (array, cb) => { + cb(Array.from(new Set(array))); +} removeDuplicates(foods, (uniqueFoods) => { console.log(`foods with duplicates removed: ${uniqueFoods}`); }); // Write a function called forEach that iterates over the provided array and passes the value and index into the callback. +// version 1 √ +const forEach = (array, cb) => { + for (let i = 0; i < array.length; i++) { + cb(array[i], i); + } +} forEach(foods, (value, index) => { console.log(`${value} is at index ${index}.`); From 04d6a18ea61e854f18d0aba735e9139d80cd5602 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 17 Jul 2017 13:10:42 -0400 Subject: [PATCH 086/523] small typo fix to version 1 of evenOccurences --- evenOccurences/evenOccurences.js | 150 +++++++++++++++---------------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index 8e864e5..2746685 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -7,87 +7,87 @@ * console.log(onlyEven); // 4 */ -// VERSION 2 √ ...from 50+ lines of code to 13 :) +// // VERSION 2 √ ...from 50+ lines of code to 13 :) +// const evenOccurence = (arr) => { +// const unique = [...new Set(arr)]; // <---------- Will Set maintain list order????? Also, still not used to spread operator. +// let count = 0; +// for (i in unique) { +// count = 0; +// for (j in arr) { +// if (unique[i] === arr[j]) { +// count++; +// } +// } +// if (count % 2 === 0) return unique[i]; +// } +// return null; +// }; + +// VERSION 1 √ +// I: array +// F(): if isUnique is false, then return null, then check total number of times +// item is in array, %2 === 0 dun, or check next until null +// O: array item - first instance of item which occurs even # of times in array const evenOccurence = (arr) => { - const unique = [...new Set(arr)]; // <---------- Will Set maintain list order????? Also, still not used to spread operator. - let count = 0; - for (i in unique) { - count = 0; - for (j in arr) { - if (unique[i] === arr[j]) { - count++; + arr; + + // I: array + // O: if (isUnique(anArray)) ? 1st unique array item : null + const isUnique = (anArray) => { + if (anArray === null) return null; + for (let i = 0; i < anArray.length; i++) { + for (let j = i + 1; j < anArray.length; j++) { + if (anArray[i] === anArray[j]) { + return anArray[i]; + } + } + } return null; + }; + + // I: array + // O: 1st item that occurs an even number of times in an array + const countNotUnique = (item, anArrayOfItems) => { + if (item === null) /* console.log(`That's some kinda ${item} item`); */ return null; + if (anArrayOfItems === null) console.log(`That's some kinda ${anArrayOfItems} anArrayOfItems array there`); // return null; + const hold = []; + if (!isUnique(item)) { + for (let i = 0; i < anArrayOfItems.length; i++) { + if (anArrayOfItems[i] === item) { + hold.push(item); + } } } - if (count % 2 === 0) return unique[i]; + return hold; } - return null; + + const oddOrEven = (dupesArray) => { + const minusOddDupe = []; + if (dupesArray === null) return null; + const count = dupesArray.length; + if (count === 0) { + return null; + } else if (count % 2 !== 0) { + for (let i = 0; i < arr.length; i++) { + if (dupesArray[0] !== arr[i]) { + minusOddDupe.push(arr[i]); + } + } + return evenOccurence(minusOddDupe); // <--------- LOOK MA, RECURSION!!!!! + } + return dupesArray[0]; + } + + return oddOrEven(countNotUnique(isUnique(arr), arr)); }; -// // VERSION 1 √ -// // I: array -// // F(): if isUnique is false, then return null, then check total number of times -// // item is in array, %2 === 0 dun, or check next until null -// // O: array item - first instance of item which occurs even # of times in array -// const evenOccurence = (arr) => { -// arr; -// -// // I: array -// // O: if (isUnique(anArray)) ? 1st unique array item : null -// const isUnique = (anArray) => { -// if (anArray === null) return null; -// for (let i = 0; i < anArray.length; i++) { -// for (let j = i + 1; j < anArray.length; j++) { -// if (anArray[i] === anArray[j]) { -// return anArray[i]; -// } -// } -// } return null; -// }; -// -// // I: array -// // O: 1st item that occurs an even number of times in an array -// const countNotUnique = (item, anArrayOfItems) => { -// if (item === null) /* console.log(`That's some kinda ${item} item`); */ return null; -// if (anArrayOfItems === null) console.log(`That's some kinda ${anArrayOfItems} anArrayOfItems array there`); // return null; -// const hold = []; -// if (!isUnique(item)) { -// for (let i = 0; i < anArrayOfItems.length; i++) { -// if (anArrayOfItems[i] === item) { -// hold.push(item); -// } -// } -// } -// return hold; -// } -// -// const oddOrEven = (dupesArray) => { -// const minusOddDupe = []; -// if (dupesArray === null) return null; -// const count = dupesArray.length; -// if (count === 0) { -// return null; -// } else if (count % 2 !== 0) { -// for (let i = 0; i < arr.length; i++) { -// if (dupesArray[0] !== arr[i]) { -// minusOddDupe.push(arr[i]); -// } -// } -// return evenOccurence(minusOddDupe); <--------- LOOK MA, RECURSION!!!!! -// } -// return dupesArray[0]; -// } -// -// return oddOrEven(countNotUnique(isUnique(arr), arr)); -// }; -// -// // evenOccurence TEST SUITE: -// // evenOccurence(); -// // console.log(`Invoking evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])} returns the repeated integer: ${evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])}`); -// // evenOccurence([5, 1, 1, 1, 1]); // <------------------------ 1 x4 >>> 1 -// // evenOccurence([1, 2, 3]) // <------------------------------- null -// // evenOccurence([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // <----- null -// // evenOccurence([5, 1, 1, 1, 6, 1, 1]); // <--------- 1 x5 >>> null -// // evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); // <--- 4 x2 >>> 4 +// evenOccurence TEST SUITE: +// evenOccurence(); +// console.log(`Invoking evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])} returns the repeated integer: ${evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])}`); +// evenOccurence([5, 1, 1, 1, 1]); // <------------------------ 1 x4 >>> 1 +// evenOccurence([1, 2, 3]) // <------------------------------- null +// evenOccurence([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // <----- null +// evenOccurence([5, 1, 1, 1, 6, 1, 1]); // <--------- 1 x5 >>> null +// evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); // <--- 4 x2 >>> 4 const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); console.log(onlyEven); // <--- 4 From 1848761542515906689fe0e9477ab0e58f99e6a7 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 17 Jul 2017 13:40:02 -0400 Subject: [PATCH 087/523] ibid --- evenOccurences/evenOccurences.js | 152 +++++++++++++++---------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index 2746685..619c4d6 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -7,91 +7,91 @@ * console.log(onlyEven); // 4 */ -// // VERSION 2 √ ...from 50+ lines of code to 13 :) -// const evenOccurence = (arr) => { -// const unique = [...new Set(arr)]; // <---------- Will Set maintain list order????? Also, still not used to spread operator. -// let count = 0; -// for (i in unique) { -// count = 0; -// for (j in arr) { -// if (unique[i] === arr[j]) { -// count++; -// } -// } -// if (count % 2 === 0) return unique[i]; -// } -// return null; -// }; - -// VERSION 1 √ -// I: array -// F(): if isUnique is false, then return null, then check total number of times -// item is in array, %2 === 0 dun, or check next until null -// O: array item - first instance of item which occurs even # of times in array +// VERSION 2 √ ...from 50+ lines of code to 13 :) const evenOccurence = (arr) => { - arr; - - // I: array - // O: if (isUnique(anArray)) ? 1st unique array item : null - const isUnique = (anArray) => { - if (anArray === null) return null; - for (let i = 0; i < anArray.length; i++) { - for (let j = i + 1; j < anArray.length; j++) { - if (anArray[i] === anArray[j]) { - return anArray[i]; - } - } - } return null; - }; - - // I: array - // O: 1st item that occurs an even number of times in an array - const countNotUnique = (item, anArrayOfItems) => { - if (item === null) /* console.log(`That's some kinda ${item} item`); */ return null; - if (anArrayOfItems === null) console.log(`That's some kinda ${anArrayOfItems} anArrayOfItems array there`); // return null; - const hold = []; - if (!isUnique(item)) { - for (let i = 0; i < anArrayOfItems.length; i++) { - if (anArrayOfItems[i] === item) { - hold.push(item); - } - } - } - return hold; - } - - const oddOrEven = (dupesArray) => { - const minusOddDupe = []; - if (dupesArray === null) return null; - const count = dupesArray.length; - if (count === 0) { - return null; - } else if (count % 2 !== 0) { - for (let i = 0; i < arr.length; i++) { - if (dupesArray[0] !== arr[i]) { - minusOddDupe.push(arr[i]); - } + const unique = [...new Set(arr)]; // <---------- Will Set maintain list order????? Also, still not used to spread operator. + let count = 0; + for (i in unique) { + count = 0; + for (j in arr) { + if (unique[i] === arr[j]) { + count++; } - return evenOccurence(minusOddDupe); // <--------- LOOK MA, RECURSION!!!!! } - return dupesArray[0]; + if (count % 2 === 0) return unique[i]; } - - return oddOrEven(countNotUnique(isUnique(arr), arr)); + return null; }; -// evenOccurence TEST SUITE: -// evenOccurence(); +// // VERSION 1 √ +// // I: array +// // F(): if isUnique is false, then return null, then check total number of times +// // item is in array, %2 === 0 dun, or check next until null +// // O: array item - first instance of item which occurs even # of times in array +// const evenOccurence = (arr) => { +// arr; +// +// // I: array +// // O: if (isUnique(anArray)) ? 1st unique array item : null +// const isUnique = (anArray) => { +// if (anArray === null) return null; +// for (let i = 0; i < anArray.length; i++) { +// for (let j = i + 1; j < anArray.length; j++) { +// if (anArray[i] === anArray[j]) { +// return anArray[i]; +// } +// } +// } return null; +// }; +// +// // I: array +// // O: 1st item that occurs an even number of times in an array +// const countNotUnique = (item, anArrayOfItems) => { +// if (item === null) /* console.log(`That's some kinda ${item} item`); */ return null; +// if (anArrayOfItems === null) console.log(`That's some kinda ${anArrayOfItems} anArrayOfItems array there`); // return null; +// const hold = []; +// if (!isUnique(item)) { +// for (let i = 0; i < anArrayOfItems.length; i++) { +// if (anArrayOfItems[i] === item) { +// hold.push(item); +// } +// } +// } +// return hold; +// } +// +// const oddOrEven = (dupesArray) => { +// const minusOddDupe = []; +// if (dupesArray === null) return null; +// const count = dupesArray.length; +// if (count === 0) { +// return null; +// } else if (count % 2 !== 0) { +// for (let i = 0; i < arr.length; i++) { +// if (dupesArray[0] !== arr[i]) { +// minusOddDupe.push(arr[i]); +// } +// } +// return evenOccurence(minusOddDupe); // <--------- LOOK MA, RECURSION!!!!! +// } +// return dupesArray[0]; +// } +// +// return oddOrEven(countNotUnique(isUnique(arr), arr)); +// }; +// +// // evenOccurence TEST SUITE: +// // evenOccurence(); // console.log(`Invoking evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])} returns the repeated integer: ${evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1])}`); // evenOccurence([5, 1, 1, 1, 1]); // <------------------------ 1 x4 >>> 1 // evenOccurence([1, 2, 3]) // <------------------------------- null // evenOccurence([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // <----- null // evenOccurence([5, 1, 1, 1, 6, 1, 1]); // <--------- 1 x5 >>> null // evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); // <--- 4 x2 >>> 4 - -const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); -console.log(onlyEven); // <--- 4 -const onlyEven2 = evenOccurence([ 1, 7, 2, 4, 5, 6, 8, 9 ]); -console.log(onlyEven2); // <--- null -const onlyEven3 = evenOccurence([ 1, 3, 3, 3, 5, 5, 5, 5, 5 ]); -console.log(onlyEven3); // <--- null +// +// const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); +// console.log(onlyEven); // <--- 4 +// const onlyEven2 = evenOccurence([ 1, 7, 2, 4, 5, 6, 8, 9 ]); +// console.log(onlyEven2); // <--- null +// const onlyEven3 = evenOccurence([ 1, 3, 3, 3, 5, 5, 5, 5, 5 ]); +// console.log(onlyEven3); // <--- null From 654b1ac0787f74dbf6e45122b50b59809d49c2ed Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 17 Jul 2017 13:40:19 -0400 Subject: [PATCH 088/523] worth adding the book reference? --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 347418c..6b51c75 100644 --- a/readme.md +++ b/readme.md @@ -7,3 +7,5 @@ ### You'll then have to resolve any merge conflicts that come up. *(Don't worry, you'll be pros at this after you're done and this is something that you'll have to do in the real world... all the time)* +*** +["Cracking the Coding Interview"](http://www.crackingthecodinginterview.com/) by Gayle Laakmann McDowell From 65b94e32e100b24dd488f166ac115d3d7a61cad0 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 17 Jul 2017 13:58:45 -0400 Subject: [PATCH 089/523] incl Tai's solution from review --- evenOccurences/evenOccurences.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index 619c4d6..f74b183 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -23,6 +23,23 @@ const evenOccurence = (arr) => { return null; }; +// // Tai's solution +// const evenOccurence = (arr) => { +// // Your code here. +// const obj = {}; +// let first; +// arr.forEach((item) => { +// if (obj[item] === undefined) return obj[item] = 1; +// if (obj[item] === 1) return obj[item] = 2; +// if (obj[item] === 2) return obj[item] = 1; +// }); +// arr.forEach((item) => { +// if(obj[item] === 2 && first === undefined) first = item; +// }); +// if (first) return first; +// return null; +// }; + // // VERSION 1 √ // // I: array // // F(): if isUnique is false, then return null, then check total number of times From f6020d474cf57431eecbf59087c9b7de0d8dc104 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 18 Jul 2017 12:12:50 -0400 Subject: [PATCH 090/523] =?UTF-8?q?cc7=20-=20forLoopTimeout=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- forLoopTimeout/forLoopTimeout.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/forLoopTimeout/forLoopTimeout.js b/forLoopTimeout/forLoopTimeout.js index ea85835..e12e549 100644 --- a/forLoopTimeout/forLoopTimeout.js +++ b/forLoopTimeout/forLoopTimeout.js @@ -4,7 +4,8 @@ // The output should be 1, 2, 3, .... 10. Right now it just prints 11. // I've been asked this three times in separate interviews. -for (var i = 1; i <= 10; i++) { +// for (var i = 1; i <= 10; i++) { +for (let i = 1; i <= 10; i++) { setTimeout(function() { // From looking at the code you would assume it would print 1 - 10 // It doesn't. Why? How can you make it print 1 - 10. From 5409868b2c536af7cf835eb45cb728f6c9c65ac9 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 18 Jul 2017 12:21:28 -0400 Subject: [PATCH 091/523] explanation of `var` vs `let` --- forLoopTimeout/forLoopTimeout.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/forLoopTimeout/forLoopTimeout.js b/forLoopTimeout/forLoopTimeout.js index e12e549..cb89896 100644 --- a/forLoopTimeout/forLoopTimeout.js +++ b/forLoopTimeout/forLoopTimeout.js @@ -1,4 +1,13 @@ // Explain what is wrong with this code and how you would fix this. + + /* As I understand it, `var` and `let` use different scoping. + I'm not sure why `var` returns 11 each time, but I am imagining + that the execution of the internal code block - the console.log() - + is executed AFTER the iteration, therefore, when the code is evaluated + the var value is set to the final pass through the iteration, === 11. + The `let` scoping, on the other hand, is constrained within the code block and + established per each iteration evaluating the console.log() contents. */ + // With ES6 there is a very, very simple way to solve this. // See if you can solve this with just ES5 JS. // The output should be 1, 2, 3, .... 10. Right now it just prints 11. From af9af9cd703b67404deb4f6e63f28de29eb8a4cd Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 18 Jul 2017 12:23:23 -0400 Subject: [PATCH 092/523] minor layout change --- evenOccurences/evenOccurences.js | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index f74b183..118e341 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -23,23 +23,6 @@ const evenOccurence = (arr) => { return null; }; -// // Tai's solution -// const evenOccurence = (arr) => { -// // Your code here. -// const obj = {}; -// let first; -// arr.forEach((item) => { -// if (obj[item] === undefined) return obj[item] = 1; -// if (obj[item] === 1) return obj[item] = 2; -// if (obj[item] === 2) return obj[item] = 1; -// }); -// arr.forEach((item) => { -// if(obj[item] === 2 && first === undefined) first = item; -// }); -// if (first) return first; -// return null; -// }; - // // VERSION 1 √ // // I: array // // F(): if isUnique is false, then return null, then check total number of times @@ -112,3 +95,20 @@ const evenOccurence = (arr) => { // console.log(onlyEven2); // <--- null // const onlyEven3 = evenOccurence([ 1, 3, 3, 3, 5, 5, 5, 5, 5 ]); // console.log(onlyEven3); // <--- null + +// // Tai's solution +// const evenOccurence = (arr) => { +// // Your code here. +// const obj = {}; +// let first; +// arr.forEach((item) => { +// if (obj[item] === undefined) return obj[item] = 1; +// if (obj[item] === 1) return obj[item] = 2; +// if (obj[item] === 2) return obj[item] = 1; +// }); +// arr.forEach((item) => { +// if(obj[item] === 2 && first === undefined) first = item; +// }); +// if (first) return first; +// return null; +// }; From 9f5b019e06e4d200ebb400a569983ead559b0053 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 18 Jul 2017 12:50:47 -0400 Subject: [PATCH 093/523] =?UTF-8?q?cc7=20-=20forLoopTimeout:=20ES5=20&=20E?= =?UTF-8?q?S6=20solution=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- forLoopTimeout/forLoopTimeout.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/forLoopTimeout/forLoopTimeout.js b/forLoopTimeout/forLoopTimeout.js index cb89896..d3780e0 100644 --- a/forLoopTimeout/forLoopTimeout.js +++ b/forLoopTimeout/forLoopTimeout.js @@ -13,11 +13,21 @@ // The output should be 1, 2, 3, .... 10. Right now it just prints 11. // I've been asked this three times in separate interviews. -// for (var i = 1; i <= 10; i++) { -for (let i = 1; i <= 10; i++) { - setTimeout(function() { - // From looking at the code you would assume it would print 1 - 10 - // It doesn't. Why? How can you make it print 1 - 10. - console.log(i); - }, 0); +// // ES6 solution √ +// for (let i = 1; i <= 10; i++) { +// setTimeout(function() { +// console.log(i); +// }, 0); +// } + +// ES5 solution +for (var i = 1; i <= 10; i++) { + var anonymousFunctionWrapper = function (i) { + return setTimeout(function() { console.log(i); }, 0); + } + anonymousFunctionWrapper(i); } + +// for (var i = 1; i <= 10; i++) { +// console.log(i); +// } From 596a6e21a2d706d77837a48bbb6e5829d60d48d1 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 18 Jul 2017 12:51:32 -0400 Subject: [PATCH 094/523] =?UTF-8?q?cc7:=20forLoopTimer:=20ES5=20&=20ES6=20?= =?UTF-8?q?=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- forLoopTimeout/forLoopTimeout.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/forLoopTimeout/forLoopTimeout.js b/forLoopTimeout/forLoopTimeout.js index d3780e0..2fc20d5 100644 --- a/forLoopTimeout/forLoopTimeout.js +++ b/forLoopTimeout/forLoopTimeout.js @@ -22,8 +22,8 @@ // ES5 solution for (var i = 1; i <= 10; i++) { - var anonymousFunctionWrapper = function (i) { - return setTimeout(function() { console.log(i); }, 0); + var anonymousFunctionWrapper = function (x) { + return setTimeout(function() { console.log(x); }, 0); } anonymousFunctionWrapper(i); } From 96d976321140284ef5827658975e8e95286d7373 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 18 Jul 2017 12:53:03 -0400 Subject: [PATCH 095/523] =?UTF-8?q?cc7=20-=20forLoopTimeout:=20ES5=20&=20E?= =?UTF-8?q?S6=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- forLoopTimeout/forLoopTimeout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forLoopTimeout/forLoopTimeout.js b/forLoopTimeout/forLoopTimeout.js index 2fc20d5..02dcb84 100644 --- a/forLoopTimeout/forLoopTimeout.js +++ b/forLoopTimeout/forLoopTimeout.js @@ -20,7 +20,7 @@ // }, 0); // } -// ES5 solution +// ES5 solution √ for (var i = 1; i <= 10; i++) { var anonymousFunctionWrapper = function (x) { return setTimeout(function() { console.log(x); }, 0); From a7522dae3e8d0103e2cf2601e3ae6792a651c037 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 19 Jul 2017 11:56:43 -0400 Subject: [PATCH 096/523] Tai's solution --- ...e_Coding_Challenge_Review_Lecture_Notes.js | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 callbackPractice/callbackPractice_Coding_Challenge_Review_Lecture_Notes.js diff --git a/callbackPractice/callbackPractice_Coding_Challenge_Review_Lecture_Notes.js b/callbackPractice/callbackPractice_Coding_Challenge_Review_Lecture_Notes.js new file mode 100644 index 0000000..0499faf --- /dev/null +++ b/callbackPractice/callbackPractice_Coding_Challenge_Review_Lecture_Notes.js @@ -0,0 +1,117 @@ +/* For today's coding challenge your job is to write functions + * so that each function call works. + * + * Example: + * + * greeting('Hey guys', (message) => { + * console.log(message); + * }); + * + * You would then define the greeting function to make the + * invocation work. + * + * const greeting = (str, cb) => { + * cb(str); + * }; + * +*/ + + +// Write a function called firstItem that passes the first item of the given +// array to the callback function + +const foods = ['pineapple', 'mango', 'ribeye', 'curry', 'tacos', 'ribeye', 'mango']; + +const firstItem = (arr, cb) => { + cb(arr[0]); +}; + +firstItem(foods, (firstItem) => { + console.log(`The first item is ${firstItem}.`); +}); + +// Write a function called getLength that passes the length of the array into +// the callback +const getLength = (arr, cb) => { + cb(arr.length); +}; + +getLength(foods, (length) => { + console.log(`The length of the array is ${length}.`); +}); + +// Write a function called last which passes the last item of the array into +// the callback +const last = (arr, cb) => { + cb(arr[arr.length - 1]); +}; + +last(foods, (lastItem) => { + console.log(`The last item in the array is ${lastItem}.`); +}); + +// Write a function called sumNums that adds two numbers and passes the result +// to the callback + +const sumNums = (x, y, cb) => { + cb(x + y); +}; + +sumNums(5, 10, (sum) => { + console.log(`The sum is ${sum}.`); +}); + +// Write a function called multiplyNums that adds two numbers and passes the +// result to the callback + +const multiplyNums = (x, y, cb) => { + cb(x * y); +}; + +multiplyNums(5, 10, (product) => { + console.log(`The product is ${product}.`); +}); + +// foods = ['pineapple', 'mango', 'ribeye', 'curry', 'tacos', 'ribeye', 'mango']; + +// Write a function called contains that checks if an item is present inside +// of the given array. Pass true to the callback if it is, otherwise pass false + +const contains = (arr, str, cb) => { + cb((arr.indexOf(str) >= 0)); +}; + +contains(foods, 'ribeye', (result) => { + console.log(result ? 'ribeye is in the array' : 'ribeye is not in the array'); +}); + +// Write a function called removeDuplicates that removes all duplicate values +// from the given array. Pass the array to the callback function. +// Do not mutate the original array. +const removeDuplicates = (arr, cb) => { + const obj = {}; + const newArr = []; + arr.forEach((item) => { + if (!obj[item]) { + obj[item] = true; + newArr.push(item); + } + }); + cb(newArr); +}; +removeDuplicates(foods, (uniqueFoods) => { + console.log(`foods with duplicates removed: ${uniqueFoods}`); +}); + +// Write a function called forEach that iterates over the provided array and +// passes the value and index into the callback. + +const forEach = (arr, cb) => { + for (let i = 0; i < arr.length; i++) { + cb(arr[i], i); + } +}; + +forEach(foods, (value, index) => { + console.log(`${value} is at index ${index}.`); +}); From aaefdbae664829b3b54df43a85a2aba06ca463cc Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 19 Jul 2017 11:58:58 -0400 Subject: [PATCH 097/523] cc8 Binary Search --- binarySearch/binarySearch.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 binarySearch/binarySearch.js diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js new file mode 100644 index 0000000..b7a345b --- /dev/null +++ b/binarySearch/binarySearch.js @@ -0,0 +1,15 @@ +/* + * Given a sorted array, find the index of the specified element + * using binary search. + * https://www.khanacademy.org/computing/computer-science/algorithms/binary-search/a/binary-search + * https://en.wikipedia.org/wiki/Binary_search_algorithm + * */ + +/** + * * const index = binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2); + * * console.log(index); // 1 +**/ + +const binarySearch = (nums, target) => { + +}; From 4cda949c272cbb08149c043d6342886b332a1359 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 19 Jul 2017 12:02:55 -0400 Subject: [PATCH 098/523] cc8 binarySearch: indexOf solution --- binarySearch/binarySearch.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index b7a345b..c416253 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -10,6 +10,10 @@ * * console.log(index); // 1 **/ +// version 1 const binarySearch = (nums, target) => { - + return nums.indexOf(target); }; + +// TEST SUITE +console.log(binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)); From e8e55bced7605b4b82d01f9e383a132c2789a68b Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 19 Jul 2017 12:10:14 -0400 Subject: [PATCH 099/523] divide & conquer --- binarySearch/binarySearch.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index c416253..4d4be6e 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -10,9 +10,20 @@ * * console.log(index); // 1 **/ -// version 1 +// // version 1: indexOf +// const binarySearch = (nums, target) => { +// return nums.indexOf(target); +// }; + +// version 2: Divide and Conquer +// PRESUMES SORTED ARRAY const binarySearch = (nums, target) => { - return nums.indexOf(target); + const min = nums[0]; + const max = nums[nums.length - 1]; + if (nums.length % 2 === 0) { + const odd = nums.length; + } else { const even = nums.length; } + console.log(`{ Minimum: ${min}, Maximum: ${max}, Odd: ${odd}, Even: ${even}`) }; // TEST SUITE From df7c88dcfb9273d01ab7356cf6b263e4a54a79c3 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 19 Jul 2017 12:12:04 -0400 Subject: [PATCH 100/523] ibid --- binarySearch/binarySearch.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index 4d4be6e..1bd9e1d 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -20,10 +20,12 @@ const binarySearch = (nums, target) => { const min = nums[0]; const max = nums[nums.length - 1]; + let odd; + let even; if (nums.length % 2 === 0) { - const odd = nums.length; - } else { const even = nums.length; } - console.log(`{ Minimum: ${min}, Maximum: ${max}, Odd: ${odd}, Even: ${even}`) + even = nums.length; + } else { odd = nums.length; } + console.log(`{ Minimum: ${min}, Maximum: ${max}, Odd: ${odd}, Even: ${even} }.`) }; // TEST SUITE From fc49be8abad6b8b4a46780424b95ab649fe35c13 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 19 Jul 2017 12:48:35 -0400 Subject: [PATCH 101/523] hacking away... --- binarySearch/binarySearch.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index 1bd9e1d..1ef8fcf 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -26,6 +26,19 @@ const binarySearch = (nums, target) => { even = nums.length; } else { odd = nums.length; } console.log(`{ Minimum: ${min}, Maximum: ${max}, Odd: ${odd}, Even: ${even} }.`) + let rangeMin = 1; + let rangeMax = max; // NOT SURE IF THIS IS WHAT I WANT CUZ VAR <==> VAR relation??? + console.log(`{ Minimum: ${min}, Maximum: ${max}, Odd: ${odd}, Even: ${even},\n\tRANGE: {rangeMin: ${rangeMin}, rangeMax: ${rangeMax}} }.`) + let guess = Math.floor((Math.random() * rangeMax) +1); + console.log(`First guess: ${guess}`); + if (guess = nums.indexOf(target)) return guess; + // Hi / Low guess + + if (even) { + guess = + } else { + = + } }; // TEST SUITE From 33d3420da269ebb63262e8196056c273465ad8a7 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 19 Jul 2017 13:59:10 -0400 Subject: [PATCH 102/523] overview --- binarySearch/binarySearch.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index 1ef8fcf..4851582 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -16,8 +16,16 @@ // }; // version 2: Divide and Conquer -// PRESUMES SORTED ARRAY +// I: A SORTED array of integers AND a target number +// O: the array index of the target (presuming array contains target - no if null check yet) +/* FUNCTION: + * randomly guess a number in the full range + * match? yes, return index + * no? compare hi or low + +*/ const binarySearch = (nums, target) => { + const targetIndex = nums.indexOf(target); const min = nums[0]; const max = nums[nums.length - 1]; let odd; @@ -33,7 +41,7 @@ const binarySearch = (nums, target) => { console.log(`First guess: ${guess}`); if (guess = nums.indexOf(target)) return guess; // Hi / Low guess - + if (even) { guess = } else { From b45b3dacd00af5e577c637c29db54f8ac6ddc890 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 00:26:26 -0400 Subject: [PATCH 103/523] re-strategerizing --- binarySearch/binarySearch.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index 4851582..7740963 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -16,13 +16,14 @@ // }; // version 2: Divide and Conquer -// I: A SORTED array of integers AND a target number -// O: the array index of the target (presuming array contains target - no if null check yet) +// I: A SORTED array (low to high) of integers AND a target number +// O: the array index of the target + // we are presuming the array actually contains target - no if null, then... check (yet) /* FUNCTION: - * randomly guess a number in the full range - * match? yes, return index - * no? compare hi or low - + * We know the target is at one of the array indexes. Take the number of indexes, divide by half round up or down. + * Is target the number at that index? return index # + * Is the target lower than the number at that index? Then do the same for the next range using the next lower index and index 0. + * is the target higher than the number at that index? Then do the same for the next range using the next higher to index.length -1. */ const binarySearch = (nums, target) => { const targetIndex = nums.indexOf(target); From d9152d1137c53cd70861cc5f28cdefb6ddbce63e Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 00:30:10 -0400 Subject: [PATCH 104/523] num in array check --- binarySearch/binarySearch.js | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index 7740963..f891f03 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -26,29 +26,9 @@ * is the target higher than the number at that index? Then do the same for the next range using the next higher to index.length -1. */ const binarySearch = (nums, target) => { - const targetIndex = nums.indexOf(target); - const min = nums[0]; - const max = nums[nums.length - 1]; - let odd; - let even; - if (nums.length % 2 === 0) { - even = nums.length; - } else { odd = nums.length; } - console.log(`{ Minimum: ${min}, Maximum: ${max}, Odd: ${odd}, Even: ${even} }.`) - let rangeMin = 1; - let rangeMax = max; // NOT SURE IF THIS IS WHAT I WANT CUZ VAR <==> VAR relation??? - console.log(`{ Minimum: ${min}, Maximum: ${max}, Odd: ${odd}, Even: ${even},\n\tRANGE: {rangeMin: ${rangeMin}, rangeMax: ${rangeMax}} }.`) - let guess = Math.floor((Math.random() * rangeMax) +1); - console.log(`First guess: ${guess}`); - if (guess = nums.indexOf(target)) return guess; - // Hi / Low guess - - if (even) { - guess = - } else { - = - } + if (nums.indexOf(target) === -1) return "Error001: target number not in array"; }; // TEST SUITE +console.log(binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20)); // ---> Error001 console.log(binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)); From 0fa06bd3672be39acfb3e45cb537f72595e54a60 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 00:34:53 -0400 Subject: [PATCH 105/523] empty array check --- binarySearch/binarySearch.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index f891f03..23fce1b 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -27,8 +27,13 @@ */ const binarySearch = (nums, target) => { if (nums.indexOf(target) === -1) return "Error001: target number not in array"; + if (nums.length < 1) return "Error002: empty array"; + minRangeIndexNum = 0 + maxRangeIndexNum = nums.length + console.log(`Index # min${minRangeIndexNum} max${maxRangeIndexNum}`) }; // TEST SUITE -console.log(binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20)); // ---> Error001 -console.log(binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)); +console.log(`Test #1: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20)}`); // ---> Error001 +console.log(`Test #2: ${binarySearch([], 20)}`); // ---> Error002 +console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); From 013fba878f8b0db1d1ad1370bc221b57dcf7e5c5 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 00:46:40 -0400 Subject: [PATCH 106/523] First! --- binarySearch/binarySearch.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index 23fce1b..c11c9ab 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -26,14 +26,21 @@ * is the target higher than the number at that index? Then do the same for the next range using the next higher to index.length -1. */ const binarySearch = (nums, target) => { - if (nums.indexOf(target) === -1) return "Error001: target number not in array"; - if (nums.length < 1) return "Error002: empty array"; - minRangeIndexNum = 0 - maxRangeIndexNum = nums.length - console.log(`Index # min${minRangeIndexNum} max${maxRangeIndexNum}`) + if (nums.length < 1) return "Error001: empty array"; + if (nums.indexOf(target) === -1) return "Error002: target number not in array"; + let minIndex = 0; + let maxIndex = nums.length - 1; + console.log(`Index # {min: ${minIndex}, max: ${maxIndex}}`) + // High or Low check + let guess = nums[Math.floor(maxIndex / 2)] + if (target === guess) { + return `FIRST TRY! The value at nums index position [${guess}] is: ${nums[guess]}`; + } + }; // TEST SUITE -console.log(`Test #1: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20)}`); // ---> Error001 -console.log(`Test #2: ${binarySearch([], 20)}`); // ---> Error002 -console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); +console.log(`Test #2: ${binarySearch([], 20)}`); // ---> Error001 +console.log(`Test #1: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20)}`); // ---> Error002 +console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> undefined +console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)}`); // ---> FIRST From b96bfeeee91a319d90d97794e77d343863251707 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 01:08:26 -0400 Subject: [PATCH 107/523] less than condition --- binarySearch/binarySearch.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index c11c9ab..0813ca6 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -33,8 +33,16 @@ const binarySearch = (nums, target) => { console.log(`Index # {min: ${minIndex}, max: ${maxIndex}}`) // High or Low check let guess = nums[Math.floor(maxIndex / 2)] - if (target === guess) { + if (target === guess) return `FIRST TRY! The value at nums index position [${guess}] is: ${nums[guess]}`; + if (target < nums[guess]) { + maxIndex = guess - 1; + let numSlice = nums.slice(minIndex, maxIndex); + console.log(`new index range {min: ${minIndex}, max: ${maxIndex}}`) + // return binarySearch(numSlice, target); + } else { + minIndex = guess + 1 + let numSlice = nums.slice(minIndex, maxIndex); } }; @@ -44,3 +52,4 @@ console.log(`Test #2: ${binarySearch([], 20)}`); // console.log(`Test #1: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20)}`); // ---> Error002 console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> undefined console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)}`); // ---> FIRST +console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> From cd08e5bfb2726a7388738871cbcaee1eb9f03529 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 01:13:38 -0400 Subject: [PATCH 108/523] greater than check - off by range of 1... --- binarySearch/binarySearch.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index 0813ca6..bbffb58 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -30,26 +30,29 @@ const binarySearch = (nums, target) => { if (nums.indexOf(target) === -1) return "Error002: target number not in array"; let minIndex = 0; let maxIndex = nums.length - 1; - console.log(`Index # {min: ${minIndex}, max: ${maxIndex}}`) + // console.log(`Index # {min: ${minIndesx}, max: ${maxIndex}}`) // High or Low check let guess = nums[Math.floor(maxIndex / 2)] if (target === guess) - return `FIRST TRY! The value at nums index position [${guess}] is: ${nums[guess]}`; + return `MATCH! The value at nums index position [${guess}] is: ${nums[guess]}`; if (target < nums[guess]) { maxIndex = guess - 1; let numSlice = nums.slice(minIndex, maxIndex); - console.log(`new index range {min: ${minIndex}, max: ${maxIndex}}`) - // return binarySearch(numSlice, target); + console.log(`LESS THAN: new index range {min: ${minIndex}, max: ${maxIndex}}`) + return binarySearch(numSlice, target); } else { minIndex = guess + 1 let numSlice = nums.slice(minIndex, maxIndex); + console.log(`GREATER THAN: new index range {min: ${minIndex}, max: ${maxIndex}}`) + return binarySearch(numSlice, target); } }; // TEST SUITE -console.log(`Test #2: ${binarySearch([], 20)}`); // ---> Error001 -console.log(`Test #1: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20)}`); // ---> Error002 -console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> undefined -console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)}`); // ---> FIRST -console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> +// console.log(`Test #1: ${binarySearch([], 20)}`); // ---> Error001 +// console.log(`Test #2: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20)}`); // ---> Error002 +// console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> undefined +// console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)}`); // ---> FIRST +// console.log(`Test #5: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> less than index range: 0, 4 +console.log(`Test #6: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 9)}`); // ---> greater than index range: 6, 9 From 2ba907248c16683f8b6879b21a95bfd2d9371821 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 01:30:07 -0400 Subject: [PATCH 109/523] getting closer... --- binarySearch/binarySearch.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index bbffb58..e8b8f26 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -33,17 +33,18 @@ const binarySearch = (nums, target) => { // console.log(`Index # {min: ${minIndesx}, max: ${maxIndex}}`) // High or Low check let guess = nums[Math.floor(maxIndex / 2)] + console.log(`GUESSING target value: ${target} is at index: nums[${guess}]`) if (target === guess) return `MATCH! The value at nums index position [${guess}] is: ${nums[guess]}`; if (target < nums[guess]) { maxIndex = guess - 1; let numSlice = nums.slice(minIndex, maxIndex); - console.log(`LESS THAN: new index range {min: ${minIndex}, max: ${maxIndex}}`) + console.log(`Target is LESS THAN value at index: nums[${guess}]: new index range {min: ${minIndex}, max: ${maxIndex}}`) return binarySearch(numSlice, target); } else { minIndex = guess + 1 let numSlice = nums.slice(minIndex, maxIndex); - console.log(`GREATER THAN: new index range {min: ${minIndex}, max: ${maxIndex}}`) + console.log(`Target is GREATER THAN value at index: nums[${guess}]: new index range {min: ${minIndex}, max: ${maxIndex}}`) return binarySearch(numSlice, target); } @@ -54,5 +55,5 @@ const binarySearch = (nums, target) => { // console.log(`Test #2: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20)}`); // ---> Error002 // console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> undefined // console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)}`); // ---> FIRST -// console.log(`Test #5: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> less than index range: 0, 4 +console.log(`Test #5: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}\n`); // ---> less than index range: 0, 4 console.log(`Test #6: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 9)}`); // ---> greater than index range: 6, 9 From 50637cb71291303c0010a7b27374b0c9ee8268d0 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 02:48:01 -0400 Subject: [PATCH 110/523] Start over next try: do not change the array - just the index range! --- binarySearch/binarySearch.js | 51 +++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index e8b8f26..176dba9 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -28,26 +28,34 @@ const binarySearch = (nums, target) => { if (nums.length < 1) return "Error001: empty array"; if (nums.indexOf(target) === -1) return "Error002: target number not in array"; - let minIndex = 0; - let maxIndex = nums.length - 1; - // console.log(`Index # {min: ${minIndesx}, max: ${maxIndex}}`) + // INDEX RANGE + let min = 0; + let max = nums.length - 1; + // console.log(`Index # {min: ${minIndesx}, max: ${max}}`) // High or Low check - let guess = nums[Math.floor(maxIndex / 2)] - console.log(`GUESSING target value: ${target} is at index: nums[${guess}]`) + // CHECK THE "MIDDLE" INDEX + let half = Math.floor(max / 2) + let guess = nums[half] + // console.log(`GUESSING target value: ${target} is at index: nums[${guess}]`) if (target === guess) return `MATCH! The value at nums index position [${guess}] is: ${nums[guess]}`; + // LESS THAN? if (target < nums[guess]) { - maxIndex = guess - 1; - let numSlice = nums.slice(minIndex, maxIndex); - console.log(`Target is LESS THAN value at index: nums[${guess}]: new index range {min: ${minIndex}, max: ${maxIndex}}`) - return binarySearch(numSlice, target); + // max = half - 1; + // let numSlice = nums.slice(min, max); + // // console.log(`Target is LESS THAN value at index: nums[${guess}]: new index range {min: ${min}, max: ${max}}`) + // return binarySearch(numSlice, target); + // GREATER THAN? } else { - minIndex = guess + 1 - let numSlice = nums.slice(minIndex, maxIndex); - console.log(`Target is GREATER THAN value at index: nums[${guess}]: new index range {min: ${minIndex}, max: ${maxIndex}}`) - return binarySearch(numSlice, target); + // let numSlice = nums.slice(half + 1); + // max = numSlice.length -1; + // half = Math.floor(max / 2) + // // console.log(numSlice); + // guess = numSlice[half]; + // // console.log(half); + // // console.log(`Target is GREATER THAN value at index: nums[${guess}]: new index range {min: ${min}, max: ${max}}`) + // return binarySearch(numSlice, target); } - }; // TEST SUITE @@ -55,5 +63,16 @@ const binarySearch = (nums, target) => { // console.log(`Test #2: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20)}`); // ---> Error002 // console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> undefined // console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)}`); // ---> FIRST -console.log(`Test #5: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}\n`); // ---> less than index range: 0, 4 -console.log(`Test #6: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 9)}`); // ---> greater than index range: 6, 9 +// console.log(`Test #5: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}\n`); // ---> +console.log(`Test #0: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0)}`); +console.log(`Test #1: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1)}`); +console.log(`Test #2: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); +console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)}`); +console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 4)}`); +console.log(`Test #5: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)}`); +console.log(`Test #6: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6)}`); +console.log(`Test #7: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 7)}`); +console.log(`Test #8: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 8)}`); +console.log(`Test #9: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 9)}`); +console.log(`Test #10:${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10)}`); +console.log(`Test #11:${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 11)}`); From f0b5a0b5bfe7ac91b63b43e33c9408e05cae3d34 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 02:58:29 -0400 Subject: [PATCH 111/523] idem --- binarySearch/binarySearch.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index 176dba9..511b3ea 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -31,7 +31,7 @@ const binarySearch = (nums, target) => { // INDEX RANGE let min = 0; let max = nums.length - 1; - // console.log(`Index # {min: ${minIndesx}, max: ${max}}`) + console.log(`Index # {min: ${min}, max: ${max}}`) // High or Low check // CHECK THE "MIDDLE" INDEX let half = Math.floor(max / 2) @@ -41,10 +41,11 @@ const binarySearch = (nums, target) => { return `MATCH! The value at nums index position [${guess}] is: ${nums[guess]}`; // LESS THAN? if (target < nums[guess]) { - // max = half - 1; + max = half; + console.log(`LESS THAN Index # {min: ${min}, max: ${max}}`) // let numSlice = nums.slice(min, max); // // console.log(`Target is LESS THAN value at index: nums[${guess}]: new index range {min: ${min}, max: ${max}}`) - // return binarySearch(numSlice, target); + return binarySearch(nums.slice(min, max), target); // GREATER THAN? } else { // let numSlice = nums.slice(half + 1); @@ -64,15 +65,15 @@ const binarySearch = (nums, target) => { // console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> undefined // console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)}`); // ---> FIRST // console.log(`Test #5: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}\n`); // ---> -console.log(`Test #0: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0)}`); -console.log(`Test #1: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1)}`); -console.log(`Test #2: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); -console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)}`); -console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 4)}`); -console.log(`Test #5: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)}`); -console.log(`Test #6: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6)}`); -console.log(`Test #7: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 7)}`); -console.log(`Test #8: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 8)}`); -console.log(`Test #9: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 9)}`); -console.log(`Test #10:${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10)}`); -console.log(`Test #11:${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 11)}`); +console.log(`Test #0: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0)}\n`); +console.log(`Test #1: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1)}\n`); +console.log(`Test #2: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}\n`); +console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)}\n`); +console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 4)}\n`); +console.log(`Test #5: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)}\n`); +console.log(`Test #6: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6)}\n`); +console.log(`Test #7: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 7)}\n`); +console.log(`Test #8: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 8)}\n`); +console.log(`Test #9: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 9)}\n`); +console.log(`Test #10:${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10)}\n`); +console.log(`Test #11:${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 11)}\n`); From d80b339ef0cf07358aae606a7a8ea1b53e2cfc79 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 10:28:42 -0400 Subject: [PATCH 112/523] idem --- binarySearch/binarySearch.js | 40 +++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index 511b3ea..5d8e408 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -26,28 +26,35 @@ * is the target higher than the number at that index? Then do the same for the next range using the next higher to index.length -1. */ const binarySearch = (nums, target) => { + console.log(nums, target); if (nums.length < 1) return "Error001: empty array"; if (nums.indexOf(target) === -1) return "Error002: target number not in array"; + if (nums.length === 1 && nums[0] === target) return `MATCH! I don't know the original index.`; // INDEX RANGE - let min = 0; - let max = nums.length - 1; - console.log(`Index # {min: ${min}, max: ${max}}`) + const range = {}; + range.min = 0; + range.max = nums.length - 1; + // console.log(`Index range: {min: ${range.min}, max: ${range.max}}`) + console.log(range); + // High or Low check // CHECK THE "MIDDLE" INDEX - let half = Math.floor(max / 2) + let half = Math.floor((range.min + range.max) / 2) let guess = nums[half] // console.log(`GUESSING target value: ${target} is at index: nums[${guess}]`) if (target === guess) return `MATCH! The value at nums index position [${guess}] is: ${nums[guess]}`; - // LESS THAN? - if (target < nums[guess]) { - max = half; - console.log(`LESS THAN Index # {min: ${min}, max: ${max}}`) + + // GUESS LESS THAN TARGET + if (nums[guess] < target) { + range.min = guess + 1; + console.log(`LESS THAN { index: ${guess}, value ${nums[guess]} } in { range: {min: ${range.min}, max: ${half}} }`) // let numSlice = nums.slice(min, max); // // console.log(`Target is LESS THAN value at index: nums[${guess}]: new index range {min: ${min}, max: ${max}}`) - return binarySearch(nums.slice(min, max), target); - // GREATER THAN? + return binarySearch(nums.slice(range.min, range.max), target); + // GUESS GREATER THAN TARGET? } else { + range.max = guess - 1; // let numSlice = nums.slice(half + 1); // max = numSlice.length -1; // half = Math.floor(max / 2) @@ -56,15 +63,16 @@ const binarySearch = (nums, target) => { // // console.log(half); // // console.log(`Target is GREATER THAN value at index: nums[${guess}]: new index range {min: ${min}, max: ${max}}`) // return binarySearch(numSlice, target); + return binarySearch(nums.slice(range.min, range.max), target); } }; -// TEST SUITE -// console.log(`Test #1: ${binarySearch([], 20)}`); // ---> Error001 -// console.log(`Test #2: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20)}`); // ---> Error002 -// console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> undefined -// console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)}`); // ---> FIRST -// console.log(`Test #5: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}\n`); // ---> +// // TEST SUITE +// // console.log(`Test #1: ${binarySearch([], 20)}`); // ---> Error001 +// // console.log(`Test #2: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20)}`); // ---> Error002 +// // console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> undefined +// // console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)}`); // ---> FIRST +// // console.log(`Test #5: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}\n`); // ---> console.log(`Test #0: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0)}\n`); console.log(`Test #1: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1)}\n`); console.log(`Test #2: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}\n`); From b68489d00d9a2020340a08513548e9afc46807fd Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 11:04:31 -0400 Subject: [PATCH 113/523] =?UTF-8?q?cc8=20binarySearch=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- binarySearch/binarySearch.js | 71 +++++++++++------------------------- 1 file changed, 21 insertions(+), 50 deletions(-) diff --git a/binarySearch/binarySearch.js b/binarySearch/binarySearch.js index 5d8e408..3113cef 100644 --- a/binarySearch/binarySearch.js +++ b/binarySearch/binarySearch.js @@ -10,70 +10,41 @@ * * console.log(index); // 1 **/ -// // version 1: indexOf +// // version 1: indexOf (gets the job done, but misses the point entirely) // const binarySearch = (nums, target) => { // return nums.indexOf(target); // }; -// version 2: Divide and Conquer +// version 2: Divide and Conquer √ + // I: A SORTED array (low to high) of integers AND a target number // O: the array index of the target - // we are presuming the array actually contains target - no if null, then... check (yet) + // we are presuming the array actually contains target + /* FUNCTION: - * We know the target is at one of the array indexes. Take the number of indexes, divide by half round up or down. - * Is target the number at that index? return index # - * Is the target lower than the number at that index? Then do the same for the next range using the next lower index and index 0. - * is the target higher than the number at that index? Then do the same for the next range using the next higher to index.length -1. + * We know the target is at one of the array indexes. Take the average of min & max range, divide by half + * If target number at that index, return index # + * Is the value at that index less than the target? Then increase the minimum to the guess index position + 1 + * Is the value at that index greater than the target? Then decrease the maximum to the guess index position - 1 */ + const binarySearch = (nums, target) => { - console.log(nums, target); if (nums.length < 1) return "Error001: empty array"; if (nums.indexOf(target) === -1) return "Error002: target number not in array"; - if (nums.length === 1 && nums[0] === target) return `MATCH! I don't know the original index.`; - // INDEX RANGE - const range = {}; - range.min = 0; - range.max = nums.length - 1; - // console.log(`Index range: {min: ${range.min}, max: ${range.max}}`) - console.log(range); - - // High or Low check - // CHECK THE "MIDDLE" INDEX - let half = Math.floor((range.min + range.max) / 2) - let guess = nums[half] - // console.log(`GUESSING target value: ${target} is at index: nums[${guess}]`) - if (target === guess) - return `MATCH! The value at nums index position [${guess}] is: ${nums[guess]}`; - - // GUESS LESS THAN TARGET - if (nums[guess] < target) { - range.min = guess + 1; - console.log(`LESS THAN { index: ${guess}, value ${nums[guess]} } in { range: {min: ${range.min}, max: ${half}} }`) - // let numSlice = nums.slice(min, max); - // // console.log(`Target is LESS THAN value at index: nums[${guess}]: new index range {min: ${min}, max: ${max}}`) - return binarySearch(nums.slice(range.min, range.max), target); - // GUESS GREATER THAN TARGET? - } else { - range.max = guess - 1; - // let numSlice = nums.slice(half + 1); - // max = numSlice.length -1; - // half = Math.floor(max / 2) - // // console.log(numSlice); - // guess = numSlice[half]; - // // console.log(half); - // // console.log(`Target is GREATER THAN value at index: nums[${guess}]: new index range {min: ${min}, max: ${max}}`) - // return binarySearch(numSlice, target); - return binarySearch(nums.slice(range.min, range.max), target); + let min = 0; + let max = nums.length - 1; + let guess; + while (min <= max) { + guess = Math.floor((min + max) / 2); + if (nums[guess] === target) { return guess } + else if (nums[guess] < target) { min = guess + 1 } + else { max = guess - 1 } } }; // // TEST SUITE -// // console.log(`Test #1: ${binarySearch([], 20)}`); // ---> Error001 -// // console.log(`Test #2: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20)}`); // ---> Error002 -// // console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}`); // ---> undefined -// // console.log(`Test #4: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)}`); // ---> FIRST -// // console.log(`Test #5: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}\n`); // ---> -console.log(`Test #0: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0)}\n`); +console.log(`\nErr Test: ${binarySearch([], 20)}\n`); // ---> Error001 +console.log(`Err Test: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0)}\n`); // ---> Error002 console.log(`Test #1: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1)}\n`); console.log(`Test #2: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)}\n`); console.log(`Test #3: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)}\n`); @@ -84,4 +55,4 @@ console.log(`Test #7: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 7)}\n`); console.log(`Test #8: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 8)}\n`); console.log(`Test #9: ${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 9)}\n`); console.log(`Test #10:${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10)}\n`); -console.log(`Test #11:${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 11)}\n`); +console.log(`Err Test:${binarySearch([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 11)}\n`); // ---> Error002 From cc0d1e349715af63db4c9a9ae3749118579ba714 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 11:07:17 -0400 Subject: [PATCH 114/523] =?UTF-8?q?CC=206=20callbackPractice=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- callbackPractice/callbackPractice.js | 1 - 1 file changed, 1 deletion(-) diff --git a/callbackPractice/callbackPractice.js b/callbackPractice/callbackPractice.js index 2844d8a..1d7b97e 100644 --- a/callbackPractice/callbackPractice.js +++ b/callbackPractice/callbackPractice.js @@ -15,7 +15,6 @@ * */ - // Write a function called firstItem that passes the first item of the given array to the callback function // version 1 √ const firstItem = (array, cb) => { From ff02e619186732f61d557d2ab7f6fc88057ba0b8 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 11:13:30 -0400 Subject: [PATCH 115/523] =?UTF-8?q?isUnique=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- isUnique/isUnique.js | 1 - 1 file changed, 1 deletion(-) diff --git a/isUnique/isUnique.js b/isUnique/isUnique.js index c284dd2..f545315 100755 --- a/isUnique/isUnique.js +++ b/isUnique/isUnique.js @@ -2,7 +2,6 @@ * Implement an algorithm to determine if a string has all unique characters. * Extra Credit - Answer this question - What if you cannot use additional data structures? */ - const isUnique = (str) => { for (let i = 0; i < str.length; i++) { for (let j = i + 1; j < str.length; j++) { From c99055a5989db169484aa6fccef8f0a6426607f6 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 11:13:46 -0400 Subject: [PATCH 116/523] =?UTF-8?q?evenOccurences=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- evenOccurences/evenOccurences.js | 1 - 1 file changed, 1 deletion(-) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index 118e341..d47be7a 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -22,7 +22,6 @@ const evenOccurence = (arr) => { } return null; }; - // // VERSION 1 √ // // I: array // // F(): if isUnique is false, then return null, then check total number of times From 536928ba48a96e3da9d98f8906135c7ed601c051 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 11:15:13 -0400 Subject: [PATCH 117/523] =?UTF-8?q?reverseCase=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reverseCase/reverseCase.js | 1 - 1 file changed, 1 deletion(-) diff --git a/reverseCase/reverseCase.js b/reverseCase/reverseCase.js index b93bba2..1582ed7 100644 --- a/reverseCase/reverseCase.js +++ b/reverseCase/reverseCase.js @@ -35,7 +35,6 @@ console.log(reverseCase(testCase2)); // ---> fSDFSDF esdfsdfDFSDFSDFSDFDSF const testCase3 = 'The quick brown Mr. Fox jumped over the lazy Mr. Dog.'; console.log(reverseCase(testCase3)); // ---> tHE QUICK BROWN mR. fOX JUMPED OVER THE LAZY mR. dOG. - // // Latoyya's solution // const reverseString = (str) => { // let newString = ''; From 6ca85b451595c7feea29fbd79310e71a15ff301c Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 20 Jul 2017 12:17:45 -0400 Subject: [PATCH 118/523] =?UTF-8?q?CC9=20brainTeasers:=20waterJugs=20?= =?UTF-8?q?=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- brainTeasers/waterJugs.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/brainTeasers/waterJugs.md b/brainTeasers/waterJugs.md index 5787394..c285c65 100644 --- a/brainTeasers/waterJugs.md +++ b/brainTeasers/waterJugs.md @@ -1,3 +1,10 @@ You have a five-quart jug, a three-quart jug, and an unlimited supply of water (but no measuring cups). How would you come up with exactly four quarts of water? Note that the jugs are oddly shaped, such that filling up exactly "half" of the jug would be impossible. + +1. Fill the 5gb +2. Pour from 5gb into 3gb - remainder 2g in 5gb +3. Empty 3gb +4. pour the 2g in 5gb into 3gb +5. fill 5gb +6. pour 1g from 5gb into 3gb - remainder 4g in 5gb. From 01ee1d767665496e7f943d2420567e008f3a27b3 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 21 Jul 2017 12:00:49 -0400 Subject: [PATCH 119/523] rough start --- array/array.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/array/array.js b/array/array.js index 7460fa2..62c42ea 100644 --- a/array/array.js +++ b/array/array.js @@ -7,3 +7,24 @@ * How do these operations compare to that of a linked list? * How does the time complexity of insertion and deletion compare to that of a linked list? */ + +class Array() { + constructor() { + this.state = { + }, + this.index = 0, + this.item = null, + } + push(item, index) { + + } + pop(item, index) { + + } + get(index) { + + } + delete(index) { + + } +} From d801c76e1138a311e12e1d887e3cbeeefb97772e Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 21 Jul 2017 12:14:18 -0400 Subject: [PATCH 120/523] push(item) ---> index++ --- array/array.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/array/array.js b/array/array.js index 62c42ea..0ac65b9 100644 --- a/array/array.js +++ b/array/array.js @@ -8,17 +8,18 @@ * How does the time complexity of insertion and deletion compare to that of a linked list? */ -class Array() { +class Array { constructor() { this.state = { }, this.index = 0, - this.item = null, + this.item = null } - push(item, index) { - + push(item) { + this.state.index = item; + this.index++; } - pop(item, index) { + pop(item) { } get(index) { @@ -27,4 +28,12 @@ class Array() { delete(index) { } -} +}; + +// TEST SUITE +const test = new Array(); +console.log(test); +test.push('chzbrgr'); +console.log(test); +test.push('salad'); +console.log(test); From ebfffe7fcd704142cf3bc126ba3b4b3fc8252d94 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 21 Jul 2017 12:39:39 -0400 Subject: [PATCH 121/523] rough --- array/array.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/array/array.js b/array/array.js index 0ac65b9..18ce788 100644 --- a/array/array.js +++ b/array/array.js @@ -8,16 +8,25 @@ * How does the time complexity of insertion and deletion compare to that of a linked list? */ +/* class Array() to construct an object such that key: value pairs are + arranged {index: item, index: item, index: item ... }, e.g. + {0: 'first item', 1: 'second item', 2: 'third item' ... (n-1): 'last item' } +*/ + class Array { - constructor() { - this.state = { - }, - this.index = 0, - this.item = null + constructor(somethingWonderful) { + this.index = 0; + this.item = somethingWonderful; + this.state = {}; + // if (somethingWonderful) { + // this.state.index = item; + // this.index++; + // } } - push(item) { - this.state.index = item; + push(addItem) { this.index++; + const node = new Array(addItem); + this.state.addItem = node; } pop(item) { @@ -31,9 +40,9 @@ class Array { }; // TEST SUITE -const test = new Array(); -console.log(test); +const test = new Array('iced tea'); +console.log('TEST#1 - Array() instance contains:', test); test.push('chzbrgr'); -console.log(test); +console.log('TEST#2 - Array() instance contains:', test); test.push('salad'); -console.log(test); +console.log('TEST#3 - Array() instance contains:', test); From 4a8110153e87e3c29c4d161cc40481f0616cca8b Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 21 Jul 2017 12:40:15 -0400 Subject: [PATCH 122/523] idem --- array/array.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/array/array.js b/array/array.js index 18ce788..ca60e11 100644 --- a/array/array.js +++ b/array/array.js @@ -18,10 +18,6 @@ class Array { this.index = 0; this.item = somethingWonderful; this.state = {}; - // if (somethingWonderful) { - // this.state.index = item; - // this.index++; - // } } push(addItem) { this.index++; From 89fbf6953442860a9cc65589da22c04fca15add0 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 21 Jul 2017 12:45:40 -0400 Subject: [PATCH 123/523] idem --- array/array.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/array/array.js b/array/array.js index ca60e11..1e1ccd5 100644 --- a/array/array.js +++ b/array/array.js @@ -24,13 +24,13 @@ class Array { const node = new Array(addItem); this.state.addItem = node; } - pop(item) { + pop(removeItem) { } - get(index) { + get(isIndex) { } - delete(index) { + delete(killIndex) { } }; From ee8e241aae77ae6028236cf50f2c127cea13d4d9 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 21 Jul 2017 13:02:20 -0400 Subject: [PATCH 124/523] push index++: value --- array/array.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/array/array.js b/array/array.js index 1e1ccd5..f30463d 100644 --- a/array/array.js +++ b/array/array.js @@ -14,15 +14,13 @@ */ class Array { - constructor(somethingWonderful) { + constructor() { this.index = 0; - this.item = somethingWonderful; this.state = {}; } push(addItem) { + this.state[this.index] = addItem; this.index++; - const node = new Array(addItem); - this.state.addItem = node; } pop(removeItem) { @@ -36,8 +34,9 @@ class Array { }; // TEST SUITE -const test = new Array('iced tea'); +const test = new Array(); console.log('TEST#1 - Array() instance contains:', test); +// console.log(`TEST#1A - Array() instance contains: ${test}`); // ---> :( test.push('chzbrgr'); console.log('TEST#2 - Array() instance contains:', test); test.push('salad'); From b6fdf1b7059ea2626efd3113823f2892168f93dc Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 21 Jul 2017 13:32:50 -0400 Subject: [PATCH 125/523] push and pop --- array/array.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/array/array.js b/array/array.js index f30463d..76f8f9d 100644 --- a/array/array.js +++ b/array/array.js @@ -22,8 +22,9 @@ class Array { this.state[this.index] = addItem; this.index++; } - pop(removeItem) { - + pop() { + this.index--; + delete this.state[this.index]; } get(isIndex) { @@ -41,3 +42,5 @@ test.push('chzbrgr'); console.log('TEST#2 - Array() instance contains:', test); test.push('salad'); console.log('TEST#3 - Array() instance contains:', test); +test.pop(); +console.log('TEST#4 - Array() instance contains:', test); From 60dc14bb05b70e7ffb80c9464c098aa0c11b80df Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 21 Jul 2017 15:03:24 -0400 Subject: [PATCH 126/523] not quite there with get... --- array/array.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/array/array.js b/array/array.js index 76f8f9d..8c6ef10 100644 --- a/array/array.js +++ b/array/array.js @@ -27,7 +27,8 @@ class Array { delete this.state[this.index]; } get(isIndex) { - + if (this.state[this.index]) console.log(this.state[isIndex]); + console.log("nope, nuthin' there"); } delete(killIndex) { @@ -44,3 +45,9 @@ test.push('salad'); console.log('TEST#3 - Array() instance contains:', test); test.pop(); console.log('TEST#4 - Array() instance contains:', test); +// console.log(`TEST#5: Q: to drink? A: ${test.get(0)}`;) +// console.log(`TEST#6: Q: to eat A: ${test.get(1)}`;) +// console.log(`TEST#7: Q: anything else? A: ${test.get(2)}`;) +test.get(0); +test.get(1); +test.get(2); From 5002faf208d0911de92b58b157a5683999e44a44 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 21 Jul 2017 16:30:59 -0400 Subject: [PATCH 127/523] =?UTF-8?q?get()=20method=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array/array.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/array/array.js b/array/array.js index 8c6ef10..4e06c15 100644 --- a/array/array.js +++ b/array/array.js @@ -27,8 +27,9 @@ class Array { delete this.state[this.index]; } get(isIndex) { - if (this.state[this.index]) console.log(this.state[isIndex]); - console.log("nope, nuthin' there"); + if (!this.state[isIndex]) return "nope, nuthin' there"; + return this.state[isIndex]; + } delete(killIndex) { @@ -43,11 +44,15 @@ test.push('chzbrgr'); console.log('TEST#2 - Array() instance contains:', test); test.push('salad'); console.log('TEST#3 - Array() instance contains:', test); -test.pop(); +test.push('iced tea'); console.log('TEST#4 - Array() instance contains:', test); -// console.log(`TEST#5: Q: to drink? A: ${test.get(0)}`;) -// console.log(`TEST#6: Q: to eat A: ${test.get(1)}`;) -// console.log(`TEST#7: Q: anything else? A: ${test.get(2)}`;) -test.get(0); -test.get(1); -test.get(2); +test.pop(); +console.log('TEST#5 - Array() instance contains:', test); +console.log(`TEST#6: Q: to eat? A: ${test.get(0)}`); +console.log(`TEST#6: Q: a side? A: ${test.get(1)}`); +console.log(`TEST#7: Q: to drink? A: ${test.get(2)}`); +console.log(`TEST#8: Q: anything else? A: ${test.get(3)}`); +// test.get(0); +// test.get(1); +// test.get(2); +// test.get(3); From 4fd352b2486f9b1e3263c9e9cc59c2cb4c0c313a Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 21 Jul 2017 16:32:43 -0400 Subject: [PATCH 128/523] idem --- array/array.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/array/array.js b/array/array.js index 4e06c15..2eb0300 100644 --- a/array/array.js +++ b/array/array.js @@ -29,6 +29,8 @@ class Array { get(isIndex) { if (!this.state[isIndex]) return "nope, nuthin' there"; return this.state[isIndex]; + // if (this.state[isIndex]) return this.state[isIndex]; + // return "nope, nuthin' there"; } delete(killIndex) { From d9f4d55c31feeebe4c378b7b3d8afe78cbd552ab Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 21 Jul 2017 16:43:43 -0400 Subject: [PATCH 129/523] delete and shifting... --- array/array.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/array/array.js b/array/array.js index 2eb0300..129c174 100644 --- a/array/array.js +++ b/array/array.js @@ -31,30 +31,30 @@ class Array { return this.state[isIndex]; // if (this.state[isIndex]) return this.state[isIndex]; // return "nope, nuthin' there"; - } delete(killIndex) { } + getAllValues() { + return Object.values(this.state); + } }; // TEST SUITE const test = new Array(); -console.log('TEST#1 - Array() instance contains:', test); +console.log('TEST# 1 - Array() instance contains:', test); // console.log(`TEST#1A - Array() instance contains: ${test}`); // ---> :( test.push('chzbrgr'); -console.log('TEST#2 - Array() instance contains:', test); +console.log('TEST# 2 - Array() instance contains:', test); test.push('salad'); -console.log('TEST#3 - Array() instance contains:', test); +console.log('TEST# 3 - Array() instance contains:', test); test.push('iced tea'); -console.log('TEST#4 - Array() instance contains:', test); +console.log('TEST# 4 - Array() instance contains:', test); +console.log('TEST# 5 - Array() instance contains:', test); +console.log(`TEST# 6: Q: to eat? A: ${test.get(0)}`); +console.log(`TEST# 7: Q: a side? A: ${test.get(1)}`); +console.log(`TEST# 8: Q: to drink? A: ${test.get(2)}`); +console.log(`TEST# 9: Q: anything else? A: ${test.get(3)}`); test.pop(); -console.log('TEST#5 - Array() instance contains:', test); -console.log(`TEST#6: Q: to eat? A: ${test.get(0)}`); -console.log(`TEST#6: Q: a side? A: ${test.get(1)}`); -console.log(`TEST#7: Q: to drink? A: ${test.get(2)}`); -console.log(`TEST#8: Q: anything else? A: ${test.get(3)}`); -// test.get(0); -// test.get(1); -// test.get(2); -// test.get(3); +console.log(`TEST#10: Q: just water? A: ${test.get(2)}`); +console.log(test.getAllValues()); From 8447481d99a3b41b2efe148aa4d00031defb174c Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 21 Jul 2017 16:52:07 -0400 Subject: [PATCH 130/523] idem --- array/array.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/array/array.js b/array/array.js index 129c174..d919e9d 100644 --- a/array/array.js +++ b/array/array.js @@ -15,7 +15,7 @@ class Array { constructor() { - this.index = 0; + this.index = 0; // <--- rename to nextIndex? this.state = {}; } push(addItem) { @@ -51,10 +51,10 @@ console.log('TEST# 3 - Array() instance contains:', test); test.push('iced tea'); console.log('TEST# 4 - Array() instance contains:', test); console.log('TEST# 5 - Array() instance contains:', test); -console.log(`TEST# 6: Q: to eat? A: ${test.get(0)}`); -console.log(`TEST# 7: Q: a side? A: ${test.get(1)}`); -console.log(`TEST# 8: Q: to drink? A: ${test.get(2)}`); -console.log(`TEST# 9: Q: anything else? A: ${test.get(3)}`); +console.log(`TEST# 6: Q: to eat? A: ${test.get(0)}`); +console.log(`TEST# 7: Q: a side? A: ${test.get(1)}`); +console.log(`TEST# 8: Q: to drink? A: ${test.get(2)}`); +console.log(`TEST# 9: Q: anything else? A: ${test.get(3)}`); test.pop(); -console.log(`TEST#10: Q: just water? A: ${test.get(2)}`); +console.log(`TEST#10: Q: just water then? A: ${test.get(2)}`); console.log(test.getAllValues()); From 092fec6c8611382ac9da751b6aff62c1e7deceba Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 21 Jul 2017 22:20:56 -0400 Subject: [PATCH 131/523] idem --- array/array.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/array/array.js b/array/array.js index d919e9d..a3dde77 100644 --- a/array/array.js +++ b/array/array.js @@ -57,4 +57,4 @@ console.log(`TEST# 8: Q: to drink? A: ${test.get(2)}`); console.log(`TEST# 9: Q: anything else? A: ${test.get(3)}`); test.pop(); console.log(`TEST#10: Q: just water then? A: ${test.get(2)}`); -console.log(test.getAllValues()); +console.log(`TEST#11: Q: what's in there?\nA: ${test.getAllValues()}`); From 6bb7da9fe4a4bbb515a0e2e4110a87aba3755e0b Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sun, 23 Jul 2017 17:00:19 -0400 Subject: [PATCH 132/523] cc10 --- array/array.js | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/array/array.js b/array/array.js index a3dde77..0a0b68c 100644 --- a/array/array.js +++ b/array/array.js @@ -32,12 +32,25 @@ class Array { // if (this.state[isIndex]) return this.state[isIndex]; // return "nope, nuthin' there"; } - delete(killIndex) { - + // will need to delete value at key#, then replace Key[n] with value at Key[n+1] + // use current this.index or last existing ondex to exit the shifting? + delete(indexValue) { + this.state[indexValue] = '' + while (indexValue < this.index) { + this.state[indexValue] =this.state[indexValue + 1]; + indexValue++; + } + this.index = indexValue - 1; } getAllValues() { return Object.values(this.state); } + getAllKeys() { + return Object.keys(this.state); + } + getAllKeysAndValues() { + return this.state + } }; // TEST SUITE @@ -50,11 +63,27 @@ test.push('salad'); console.log('TEST# 3 - Array() instance contains:', test); test.push('iced tea'); console.log('TEST# 4 - Array() instance contains:', test); -console.log('TEST# 5 - Array() instance contains:', test); -console.log(`TEST# 6: Q: to eat? A: ${test.get(0)}`); -console.log(`TEST# 7: Q: a side? A: ${test.get(1)}`); -console.log(`TEST# 8: Q: to drink? A: ${test.get(2)}`); -console.log(`TEST# 9: Q: anything else? A: ${test.get(3)}`); +console.log(`TEST# 5: Q: to eat? A: ${test.get(0)}`); +console.log(`TEST# 6: Q: a side? A: ${test.get(1)}`); +console.log(`TEST# 7: Q: to drink? A: ${test.get(2)}`); +console.log(`TEST# 8: Q: anything else? A: ${test.get(3)}`); test.pop(); -console.log(`TEST#10: Q: just water then? A: ${test.get(2)}`); -console.log(`TEST#11: Q: what's in there?\nA: ${test.getAllValues()}`); +console.log(`TEST# 9: Q: just water then? A: ${test.get(2)}`); +console.log(`TEST#10: Q: what's for dinner?\nA: ${test.getAllValues()}`); +test.push('this'); +test.push('that'); +test.push('the other thing'); +test.push('something else'); +test.push('another thing'); +test.push('aaaaand another thing'); +console.log(`TEST#11: Q: what all's in there?\nA: ${test.getAllValues()}`); +console.log(`TEST#12: Q: what all's where in there?\nA: ${test.getAllKeys()}`); +console.log(`TEST#13: Q: which what all's where in there?\nA: ${test.getAllKeysAndValues()}`); +console.log(test.getAllKeysAndValues()); +test.delete(5); +console.log(`TEST#14: Q: did something get deleted?\nA: ${test.getAllKeysAndValues()}`); +console.log(test.getAllKeysAndValues()); +console.log(`TEST#15: Q: What's the index set to?\nA: ${test.index}`); +test.push('well lookie thar!') +console.log(`TEST#16: Q: Did I add it to the right place?\nA: ${test.getAllKeysAndValues()}`); +console.log(test.getAllKeysAndValues()); From a74dd6cf711b2bf1b4ce47092d03050651ff90e3 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sun, 23 Jul 2017 17:05:26 -0400 Subject: [PATCH 133/523] =?UTF-8?q?Array=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array/array.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/array/array.js b/array/array.js index 0a0b68c..75d7324 100644 --- a/array/array.js +++ b/array/array.js @@ -15,16 +15,16 @@ class Array { constructor() { - this.index = 0; // <--- rename to nextIndex? + this.nextIndex = 0; this.state = {}; } push(addItem) { - this.state[this.index] = addItem; - this.index++; + this.state[this.nextIndex] = addItem; + this.nextIndex++; } pop() { - this.index--; - delete this.state[this.index]; + this.nextIndex--; + delete this.state[this.nextIndex]; } get(isIndex) { if (!this.state[isIndex]) return "nope, nuthin' there"; @@ -36,11 +36,11 @@ class Array { // use current this.index or last existing ondex to exit the shifting? delete(indexValue) { this.state[indexValue] = '' - while (indexValue < this.index) { + while (indexValue < this.nextIndex) { this.state[indexValue] =this.state[indexValue + 1]; indexValue++; } - this.index = indexValue - 1; + this.nextIndex = indexValue - 1; } getAllValues() { return Object.values(this.state); @@ -83,7 +83,7 @@ console.log(test.getAllKeysAndValues()); test.delete(5); console.log(`TEST#14: Q: did something get deleted?\nA: ${test.getAllKeysAndValues()}`); console.log(test.getAllKeysAndValues()); -console.log(`TEST#15: Q: What's the index set to?\nA: ${test.index}`); +console.log(`TEST#15: Q: What's the index set to?\nA: ${test.nextIndex}`); test.push('well lookie thar!') console.log(`TEST#16: Q: Did I add it to the right place?\nA: ${test.getAllKeysAndValues()}`); console.log(test.getAllKeysAndValues()); From b3e0395e0a60c2f4ecf3eeedbc6f5fd4171c174e Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sun, 23 Jul 2017 17:12:29 -0400 Subject: [PATCH 134/523] =?UTF-8?q?Array=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array/array.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/array/array.js b/array/array.js index 75d7324..4c0433c 100644 --- a/array/array.js +++ b/array/array.js @@ -14,14 +14,17 @@ */ class Array { + // starts empty - todo: set up Array class so it can take initializing value(s), e.g. `Array(...args)` constructor() { this.nextIndex = 0; this.state = {}; } + // todo: push(...args) push(addItem) { this.state[this.nextIndex] = addItem; this.nextIndex++; } + // todo: push(#) to invoke push() # of times or from a index to the end pop() { this.nextIndex--; delete this.state[this.nextIndex]; @@ -29,11 +32,11 @@ class Array { get(isIndex) { if (!this.state[isIndex]) return "nope, nuthin' there"; return this.state[isIndex]; - // if (this.state[isIndex]) return this.state[isIndex]; - // return "nope, nuthin' there"; } - // will need to delete value at key#, then replace Key[n] with value at Key[n+1] - // use current this.index or last existing ondex to exit the shifting? + // delete value at Key# (i.e. array "index"), then replace Key[n] with value at Key[n+1] + // use current this.nextIndex (or last existing index?) to exit the shifting? + // set nextIndex to last Key# + // todo: delete(indexRange)? delete(indexValue) { this.state[indexValue] = '' while (indexValue < this.nextIndex) { From 2dbde22c6d2321f86fea6216750f738ee00c6ef1 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sun, 23 Jul 2017 17:32:25 -0400 Subject: [PATCH 135/523] =?UTF-8?q?Array=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array/array.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/array/array.js b/array/array.js index 4c0433c..3a82b79 100644 --- a/array/array.js +++ b/array/array.js @@ -14,25 +14,25 @@ */ class Array { - // starts empty - todo: set up Array class so it can take initializing value(s), e.g. `Array(...args)` + // starts empty + // todo: set up Array class so it can take initializing value(s), e.g. `Array(...args)` constructor() { this.nextIndex = 0; this.state = {}; } + // todo: push(...args) push(addItem) { this.state[this.nextIndex] = addItem; this.nextIndex++; } - // todo: push(#) to invoke push() # of times or from a index to the end + + // todo: pop(#) to invoke push() # of times or from a index to the end pop() { this.nextIndex--; delete this.state[this.nextIndex]; } - get(isIndex) { - if (!this.state[isIndex]) return "nope, nuthin' there"; - return this.state[isIndex]; - } + // delete value at Key# (i.e. array "index"), then replace Key[n] with value at Key[n+1] // use current this.nextIndex (or last existing index?) to exit the shifting? // set nextIndex to last Key# @@ -45,6 +45,12 @@ class Array { } this.nextIndex = indexValue - 1; } + + // Helper functions + get(isIndex) { + if (!this.state[isIndex]) return "nope, nuthin' there"; + return this.state[isIndex]; + } getAllValues() { return Object.values(this.state); } @@ -76,17 +82,18 @@ console.log(`TEST#10: Q: what's for dinner?\nA: ${test.getAllValues()}`); test.push('this'); test.push('that'); test.push('the other thing'); -test.push('something else'); +test.push('something'); test.push('another thing'); test.push('aaaaand another thing'); console.log(`TEST#11: Q: what all's in there?\nA: ${test.getAllValues()}`); console.log(`TEST#12: Q: what all's where in there?\nA: ${test.getAllKeys()}`); -console.log(`TEST#13: Q: which what all's where in there?\nA: ${test.getAllKeysAndValues()}`); +console.log(`TEST#13: Q: which what all's where in there?\nA: ${test.getAllKeysAndValues()}`); // <---- how to get the object printed and not the type? console.log(test.getAllKeysAndValues()); test.delete(5); -console.log(`TEST#14: Q: did something get deleted?\nA: ${test.getAllKeysAndValues()}`); +console.log(`TEST#14: Q: did "something" get deleted?\nA: ${test.getAllKeysAndValues()}`); console.log(test.getAllKeysAndValues()); -console.log(`TEST#15: Q: What's the index set to?\nA: ${test.nextIndex}`); +console.log(`TEST#15: Q: What's the index set to?\nA: The next inde location is: ${test.nextIndex}`); test.push('well lookie thar!') console.log(`TEST#16: Q: Did I add it to the right place?\nA: ${test.getAllKeysAndValues()}`); console.log(test.getAllKeysAndValues()); +console.log(test.global; From 5d52b1d01a2ae0a070edd0124b2c52131c7a8799 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sun, 23 Jul 2017 17:39:50 -0400 Subject: [PATCH 136/523] =?UTF-8?q?Array=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array/array.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/array/array.js b/array/array.js index 3a82b79..ad4fa36 100644 --- a/array/array.js +++ b/array/array.js @@ -33,6 +33,12 @@ class Array { delete this.state[this.nextIndex]; } + // todo: get(...args) + get(isIndex) { + if (!this.state[isIndex]) return "nope"; + return this.state[isIndex]; + } + // delete value at Key# (i.e. array "index"), then replace Key[n] with value at Key[n+1] // use current this.nextIndex (or last existing index?) to exit the shifting? // set nextIndex to last Key# @@ -47,10 +53,6 @@ class Array { } // Helper functions - get(isIndex) { - if (!this.state[isIndex]) return "nope, nuthin' there"; - return this.state[isIndex]; - } getAllValues() { return Object.values(this.state); } @@ -72,12 +74,12 @@ test.push('salad'); console.log('TEST# 3 - Array() instance contains:', test); test.push('iced tea'); console.log('TEST# 4 - Array() instance contains:', test); -console.log(`TEST# 5: Q: to eat? A: ${test.get(0)}`); -console.log(`TEST# 6: Q: a side? A: ${test.get(1)}`); -console.log(`TEST# 7: Q: to drink? A: ${test.get(2)}`); -console.log(`TEST# 8: Q: anything else? A: ${test.get(3)}`); +console.log(`TEST# 5: Q: to eat? A: ${test.get(0)}`); +console.log(`TEST# 6: Q: a side? A: ${test.get(1)}`); +console.log(`TEST# 7: Q: to drink? A: ${test.get(2)}`); +console.log(`TEST# 8: Q: want some sodaPOP? A: ${test.get(3)}`); test.pop(); -console.log(`TEST# 9: Q: just water then? A: ${test.get(2)}`); +console.log(`TEST# 9: Q: just water then? A: ${test.get(2)}`); console.log(`TEST#10: Q: what's for dinner?\nA: ${test.getAllValues()}`); test.push('this'); test.push('that'); @@ -96,4 +98,3 @@ console.log(`TEST#15: Q: What's the index set to?\nA: The next inde location is: test.push('well lookie thar!') console.log(`TEST#16: Q: Did I add it to the right place?\nA: ${test.getAllKeysAndValues()}`); console.log(test.getAllKeysAndValues()); -console.log(test.global; From de64a34d532c173587a59597998078b41879139d Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sun, 23 Jul 2017 17:57:20 -0400 Subject: [PATCH 137/523] =?UTF-8?q?Array=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array/array.js | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/array/array.js b/array/array.js index ad4fa36..5340884 100644 --- a/array/array.js +++ b/array/array.js @@ -18,25 +18,25 @@ class Array { // todo: set up Array class so it can take initializing value(s), e.g. `Array(...args)` constructor() { this.nextIndex = 0; - this.state = {}; + this.listObject = {}; } // todo: push(...args) push(addItem) { - this.state[this.nextIndex] = addItem; + this.listObject[this.nextIndex] = addItem; this.nextIndex++; } // todo: pop(#) to invoke push() # of times or from a index to the end pop() { this.nextIndex--; - delete this.state[this.nextIndex]; + delete this.listObject[this.nextIndex]; } // todo: get(...args) get(isIndex) { - if (!this.state[isIndex]) return "nope"; - return this.state[isIndex]; + if (!this.listObject[isIndex]) return "nope"; + return this.listObject[isIndex]; } // delete value at Key# (i.e. array "index"), then replace Key[n] with value at Key[n+1] @@ -44,9 +44,9 @@ class Array { // set nextIndex to last Key# // todo: delete(indexRange)? delete(indexValue) { - this.state[indexValue] = '' + this.listObject[indexValue] = '' while (indexValue < this.nextIndex) { - this.state[indexValue] =this.state[indexValue + 1]; + this.listObject[indexValue] = this.listObject[indexValue + 1]; indexValue++; } this.nextIndex = indexValue - 1; @@ -54,13 +54,13 @@ class Array { // Helper functions getAllValues() { - return Object.values(this.state); + return Object.values(this.listObject); } getAllKeys() { - return Object.keys(this.state); + return Object.keys(this.listObject); } getAllKeysAndValues() { - return this.state + return this.listObject; } }; @@ -94,7 +94,21 @@ console.log(test.getAllKeysAndValues()); test.delete(5); console.log(`TEST#14: Q: did "something" get deleted?\nA: ${test.getAllKeysAndValues()}`); console.log(test.getAllKeysAndValues()); -console.log(`TEST#15: Q: What's the index set to?\nA: The next inde location is: ${test.nextIndex}`); +console.log(`TEST#15: Q: What's the index set to?\nA: The next index location is: ${test.nextIndex}`); test.push('well lookie thar!') console.log(`TEST#16: Q: Did I add it to the right place?\nA: ${test.getAllKeysAndValues()}`); console.log(test.getAllKeysAndValues()); +test.push('more stuff!') +console.log(`TEST#17: Q: Wanna add some more stuff?\nA: ${test.getAllKeysAndValues()}`); +console.log(test.getAllKeysAndValues()); +test.delete(1); +test.delete(3); +test.delete(5); +console.log(`TEST#18: Q: What just happened???\nA: ${test.getAllKeysAndValues()}`); +console.log(test.getAllKeysAndValues()); +test.push('even more stuff!') +test.push('so much stuff!') +test.push('and even more stuff!') +test.push('never ending stuff!!!') +console.log(`TEST#17: Q: Wanna add some more stuff?\nA: ${test.getAllKeysAndValues()}`); +console.log(test.getAllKeysAndValues()); From 2684b405e35f4b17e16654452f1dcd6eb5de1704 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sun, 23 Jul 2017 18:05:24 -0400 Subject: [PATCH 138/523] =?UTF-8?q?Array=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array/array.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/array/array.js b/array/array.js index 5340884..a8c2daa 100644 --- a/array/array.js +++ b/array/array.js @@ -111,4 +111,4 @@ test.push('so much stuff!') test.push('and even more stuff!') test.push('never ending stuff!!!') console.log(`TEST#17: Q: Wanna add some more stuff?\nA: ${test.getAllKeysAndValues()}`); -console.log(test.getAllKeysAndValues()); +console.log(JSON.stringify(test.getAllKeysAndValues())); From 5df97196a7b3127b64a1f95250ed71edb8b1f3af Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 24 Jul 2017 12:57:49 -0400 Subject: [PATCH 139/523] rough start --- stringCompression/stringCompression.js | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/stringCompression/stringCompression.js b/stringCompression/stringCompression.js index 48db571..fcb1c81 100644 --- a/stringCompression/stringCompression.js +++ b/stringCompression/stringCompression.js @@ -4,3 +4,39 @@ // If the "compressed" string would not become smaller than the original string, // your method should return the original string. // You can assume the string has only uppercase and lowercase letters (a - z). + + +// const compress = function(str) { +// // ... +// } + +class Compressor { + constructor(upperOrLowerCaseString) { + this.string = upperOrLowerCaseString; + this.count = 1; + this.arr = []; + this.worthCompressing = (compareStringLength ? true : false) + } + + totalRepetitions() { + for (let i = 0; i < this.string.length; i++) { + if (this.string.charAt(i) === this.string.charAt(i + 1)) { this.count++; } + } + return this.count + } + + compareStringLength(str) { + // if there are no letters repeated more than twice, not worth compressing + } + +} + + + + +// TEST SUITE +const test = new Compressor('aabcccccaaa'); +// const test = new Compressor('abca'); +console.log(test); +console.log(test.totalRepetitions()); // ---> 8 +console.log(test.compareStringLength()); // ---> a2b1c5a3 From 90774a4c7c46a76ca8b470d7436b85a9f38c5189 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 24 Jul 2017 13:17:30 -0400 Subject: [PATCH 140/523] =?UTF-8?q?array=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array/array.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/array/array.js b/array/array.js index a8c2daa..03f6712 100644 --- a/array/array.js +++ b/array/array.js @@ -8,9 +8,9 @@ * How does the time complexity of insertion and deletion compare to that of a linked list? */ -/* class Array() to construct an object such that key: value pairs are - arranged {index: item, index: item, index: item ... }, e.g. - {0: 'first item', 1: 'second item', 2: 'third item' ... (n-1): 'last item' } +/* class Array() to construct an object such that key: value pairs are arranged + { index: item, index: item, index: item, ... index: item }, e.g. + {0: 'first item', 1: 'second item', 2: 'third item', ... (n-1): 'last item' } */ class Array { @@ -20,12 +20,14 @@ class Array { this.nextIndex = 0; this.listObject = {}; } + // CONVENTION: INCLUDE A LENGTH PROPERTY // todo: push(...args) push(addItem) { this.listObject[this.nextIndex] = addItem; this.nextIndex++; } + // CONVENTION: RETURN THE VALUE WHICH HAS BEEN DELETED // todo: pop(#) to invoke push() # of times or from a index to the end pop() { From bed1277f40cac3ca544285daa51663bea924cbdb Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 24 Jul 2017 14:49:31 -0400 Subject: [PATCH 141/523] Sean's solution --- array/sean_array.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 array/sean_array.js diff --git a/array/sean_array.js b/array/sean_array.js new file mode 100644 index 0000000..54d808e --- /dev/null +++ b/array/sean_array.js @@ -0,0 +1,31 @@ +class ObjArray { + constructor() { + this.storage = {}; + this.length = 0; + } + + get(index) { + return this.storage[index]; + } + + delete(index) { + delete this.storage[index]; + for (let i = index; i <= this.length; i++) { + this.storage[i] = this.storage[i + 1]; + } + this.length--; + } + + push(element) { + this.storage[this.length] = element; + this.length++; + } + + pop() { + const lastIndex = this.length - 1; + const valueToReturn = this.storage[lastIndex]; + delete this.storage[lastIndex]; + this.length--; + return valueToReturn; + } +} From 69c84e4a30baed876a3be3fda2f515331e41f47c Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 24 Jul 2017 14:49:39 -0400 Subject: [PATCH 142/523] =?UTF-8?q?Array=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array/array.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/array/array.js b/array/array.js index 03f6712..589387d 100644 --- a/array/array.js +++ b/array/array.js @@ -13,7 +13,7 @@ {0: 'first item', 1: 'second item', 2: 'third item', ... (n-1): 'last item' } */ -class Array { +class ObjArray { // starts empty // todo: set up Array class so it can take initializing value(s), e.g. `Array(...args)` constructor() { @@ -67,15 +67,15 @@ class Array { }; // TEST SUITE -const test = new Array(); -console.log('TEST# 1 - Array() instance contains:', test); +const test = new ObjArray(); +console.log('TEST# 1 - ObjArray() instance contains:', test); // console.log(`TEST#1A - Array() instance contains: ${test}`); // ---> :( test.push('chzbrgr'); -console.log('TEST# 2 - Array() instance contains:', test); +console.log('TEST# 2 - ObjArray() instance contains:', test); test.push('salad'); -console.log('TEST# 3 - Array() instance contains:', test); +console.log('TEST# 3 - ObjArray() instance contains:', test); test.push('iced tea'); -console.log('TEST# 4 - Array() instance contains:', test); +console.log('TEST# 4 - ObjArray() instance contains:', test); console.log(`TEST# 5: Q: to eat? A: ${test.get(0)}`); console.log(`TEST# 6: Q: a side? A: ${test.get(1)}`); console.log(`TEST# 7: Q: to drink? A: ${test.get(2)}`); @@ -91,7 +91,7 @@ test.push('another thing'); test.push('aaaaand another thing'); console.log(`TEST#11: Q: what all's in there?\nA: ${test.getAllValues()}`); console.log(`TEST#12: Q: what all's where in there?\nA: ${test.getAllKeys()}`); -console.log(`TEST#13: Q: which what all's where in there?\nA: ${test.getAllKeysAndValues()}`); // <---- how to get the object printed and not the type? +console.log(`TEST#13: Q: which what all's where in there?\nA: ${test.getAllKeysAndValues()}`); // <---- how to get the object printed and not the type? JSON.stringify() console.log(test.getAllKeysAndValues()); test.delete(5); console.log(`TEST#14: Q: did "something" get deleted?\nA: ${test.getAllKeysAndValues()}`); @@ -113,4 +113,5 @@ test.push('so much stuff!') test.push('and even more stuff!') test.push('never ending stuff!!!') console.log(`TEST#17: Q: Wanna add some more stuff?\nA: ${test.getAllKeysAndValues()}`); -console.log(JSON.stringify(test.getAllKeysAndValues())); +console.log(test.getAllKeysAndValues()); +console.log(`Q: easier to read?\nA: ${JSON.stringify(test.getAllKeysAndValues())}`); From 4c9d771b44c5b8594152e3dfc69dfa2b3171a8f1 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 25 Jul 2017 11:17:16 -0400 Subject: [PATCH 143/523] basic compression, no bloat stop --- stringCompression/stringCompression.js | 42 ++++++++++---------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/stringCompression/stringCompression.js b/stringCompression/stringCompression.js index fcb1c81..c93b8a2 100644 --- a/stringCompression/stringCompression.js +++ b/stringCompression/stringCompression.js @@ -6,37 +6,27 @@ // You can assume the string has only uppercase and lowercase letters (a - z). -// const compress = function(str) { -// // ... -// } -class Compressor { - constructor(upperOrLowerCaseString) { - this.string = upperOrLowerCaseString; - this.count = 1; - this.arr = []; - this.worthCompressing = (compareStringLength ? true : false) - } - totalRepetitions() { - for (let i = 0; i < this.string.length; i++) { - if (this.string.charAt(i) === this.string.charAt(i + 1)) { this.count++; } - } - return this.count - } +const compressor = function(str) { + // halt if compressing would make a longer string - compareStringLength(str) { - // if there are no letters repeated more than twice, not worth compressing + // compression algorithm + const arr = []; + let count = 1; + for (let i = 0; i < str.length; i++) { + if (str[i] === str[i + 1]) { + count++; + } else if ((str[i] != str[i + 1])) { + arr.push(`${str[i]}${count}`); + count = 1 + } } - -} - - + return arr; +}; // TEST SUITE -const test = new Compressor('aabcccccaaa'); -// const test = new Compressor('abca'); +const test = compressor('aabcccccaaa'); // ---> a2b1c5a3 console.log(test); -console.log(test.totalRepetitions()); // ---> 8 -console.log(test.compareStringLength()); // ---> a2b1c5a3 +console.log(compressor('abca')); // ---> a1b1c1a1 From f924b10c64665fdabd142e1425a3addd868a452e Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 25 Jul 2017 11:27:06 -0400 Subject: [PATCH 144/523] =?UTF-8?q?stringCompression=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stringCompression/stringCompression.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/stringCompression/stringCompression.js b/stringCompression/stringCompression.js index c93b8a2..a874a69 100644 --- a/stringCompression/stringCompression.js +++ b/stringCompression/stringCompression.js @@ -9,7 +9,11 @@ const compressor = function(str) { - // halt if compressing would make a longer string + // is there a simple check prevent the algorithm from running + // if it would make a longer string? Seems like not having to + // calculate the algorithm first to then evaluate if it + // made the string longer would make for a much better + // Order of Complexity...? // compression algorithm const arr = []; @@ -22,11 +26,17 @@ const compressor = function(str) { count = 1 } } - return arr; + const compressed = arr.join(''); + + // halt if compressing would make a longer string + if (str.length <= compressed.length) return `inadequate algorithm`; + return compressed; }; // TEST SUITE const test = compressor('aabcccccaaa'); // ---> a2b1c5a3 console.log(test); -console.log(compressor('abca')); // ---> a1b1c1a1 +console.log(compressor('abca')); // ---> inadequate algorithm +console.log(compressor('aabbcc')); // ---> inadequate algorithm +console.log(compressor('aabbccc')); // ---> inadequate algorithm From 9bdda8ad3dee5e8de7350601d8dc3621e7940bbd Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 25 Jul 2017 12:33:34 -0400 Subject: [PATCH 145/523] =?UTF-8?q?cc12=20operators=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- operators/operators.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/operators/operators.js b/operators/operators.js index b6dbed4..9747d6d 100644 --- a/operators/operators.js +++ b/operators/operators.js @@ -4,3 +4,39 @@ * Now for the tricky part: you can only use the + and - operators to implement these functions. * For division just drop the remainder. */ + +const multiply = function(a, b) { + const arr = new Array(b).fill(a); + const product = arr.reduce((a, b) => a + b, 0); + return product; +}; + +const divide = function(x, y) { + let count = 0; + while (x - y >= 0) { + x -= y; + count++; + } + return `${count} remainder ${x}`; +}; + +const modulo = function(phi, psi) { + let count = 0; + while (phi - psi >= 0) { + phi -= psi; + count++; + } + return phi; +}; + + +// TEST SUITE +// multiplication +console.log(multiply(2, 10)) // ---> 20 +console.log(multiply(1, 1)) // ---> 1 +// division +console.log(divide(121, 11)) // ---> 11 remainder 0 +console.log(divide(123, 11)) // ---> 11 remainder 2 +// modulo +console.log(modulo(15000, 11)) // ---> 7 +console.log(modulo(123, 11)) // ---> 2 From 2295e815254f31c9645d01962dd990d54c89b878 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 25 Jul 2017 12:53:58 -0400 Subject: [PATCH 146/523] =?UTF-8?q?cc11=20stringCompression=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stringCompression/stringCompression.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stringCompression/stringCompression.js b/stringCompression/stringCompression.js index a874a69..53d9e35 100644 --- a/stringCompression/stringCompression.js +++ b/stringCompression/stringCompression.js @@ -28,7 +28,7 @@ const compressor = function(str) { } const compressed = arr.join(''); - // halt if compressing would make a longer string + // return original string if compressing made a longer string if (str.length <= compressed.length) return `inadequate algorithm`; return compressed; }; From ebb3cb27105fdb5c908c64d04d3398c2d4029816 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 25 Jul 2017 13:01:12 -0400 Subject: [PATCH 147/523] =?UTF-8?q?cc11=20stringCompression=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stringCompression/stringCompression.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stringCompression/stringCompression.js b/stringCompression/stringCompression.js index 53d9e35..d4d430c 100644 --- a/stringCompression/stringCompression.js +++ b/stringCompression/stringCompression.js @@ -39,4 +39,4 @@ const test = compressor('aabcccccaaa'); // ---> a2b1c5a3 console.log(test); console.log(compressor('abca')); // ---> inadequate algorithm console.log(compressor('aabbcc')); // ---> inadequate algorithm -console.log(compressor('aabbccc')); // ---> inadequate algorithm +console.log(compressor('aabbccc')); // ---> a2b2c3 From 84463d14fdcb107baec1b18f5d5fe6d297284d21 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 25 Jul 2017 13:07:07 -0400 Subject: [PATCH 148/523] =?UTF-8?q?cc11=20stringCompression=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stringCompression/stringCompression.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/stringCompression/stringCompression.js b/stringCompression/stringCompression.js index d4d430c..0b04499 100644 --- a/stringCompression/stringCompression.js +++ b/stringCompression/stringCompression.js @@ -5,9 +5,6 @@ // your method should return the original string. // You can assume the string has only uppercase and lowercase letters (a - z). - - - const compressor = function(str) { // is there a simple check prevent the algorithm from running // if it would make a longer string? Seems like not having to From 1e5bd4481b8257572881d02b954e00750d904089 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 25 Jul 2017 13:41:48 -0400 Subject: [PATCH 149/523] =?UTF-8?q?cc11=20stringCompression=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stringCompression/stringCompression.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/stringCompression/stringCompression.js b/stringCompression/stringCompression.js index 0b04499..f5b4a49 100644 --- a/stringCompression/stringCompression.js +++ b/stringCompression/stringCompression.js @@ -24,16 +24,16 @@ const compressor = function(str) { } } const compressed = arr.join(''); - - // return original string if compressing made a longer string - if (str.length <= compressed.length) return `inadequate algorithm`; - return compressed; + // // return original string if compressing made a longer string + // if (str.length <= compressed.length) return `inadequate algorithm`; + // return compressed; + // ternary + return str.length <= compressed.length ? str : compressed }; - // TEST SUITE const test = compressor('aabcccccaaa'); // ---> a2b1c5a3 console.log(test); -console.log(compressor('abca')); // ---> inadequate algorithm -console.log(compressor('aabbcc')); // ---> inadequate algorithm +console.log(compressor('abca')); // ---> abca: inadequate compression algorithm +console.log(compressor('aabbcc')); // ---> aabbcc: inadequate compression algorithm console.log(compressor('aabbccc')); // ---> a2b2c3 From 2da2c8f2bcd05d4979da14307f0b3236bb6deabe Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 26 Jul 2017 12:13:37 -0400 Subject: [PATCH 150/523] cc13 constructors wip --- constructors/constructors.js | 63 +++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/constructors/constructors.js b/constructors/constructors.js index 34310c9..5be1f3c 100644 --- a/constructors/constructors.js +++ b/constructors/constructors.js @@ -21,4 +21,65 @@ * * This is how you would structure the game objects in an actual game * application in Unity or another similar framework. - */ \ No newline at end of file + */ + +class NPC { + constructor(props) { + this.state = { + name: '', + weapon: '', + health: '', + strength: '', + level: '', + } + } +} +// * NPC -> Humanoid, Animal, Plant +class Humanoid extends NPC { + constructor(props) { + super(props); + } +} +class Animal extends NPC { + constructor(props) { + super(props); + } +} +class Plant extends NPC { + constructor(props) { + super(props); + } +} +// * Humanoid -> Human, Elf, Orc +class Human extends Humanoid { // Human props relative to roll of dice + constructor(props) { + super(props); + } +} +class Elf extends Humanoid { + constructor(props) { + super(props); + } +} +class Orc extends Humanoid { + constructor(props) { + super(props) + } +} +// * Animal -> Bear, Wolf +class Bear extends Animal { + constructor(props) { + super(props) + } +} +class Wolf extends Animal { + constructor(props) { + super(props) + } +} +// * Plant -> FleshEatingDaisy +class FleshEatingDaisy { + constructor(props) { + super(props) + } +} From e54da28b8be04094587dbd151598e30aa76e9797 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 26 Jul 2017 12:24:47 -0400 Subject: [PATCH 151/523] this.state --- constructors/constructors.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/constructors/constructors.js b/constructors/constructors.js index 5be1f3c..cf78000 100644 --- a/constructors/constructors.js +++ b/constructors/constructors.js @@ -38,48 +38,62 @@ class NPC { class Humanoid extends NPC { constructor(props) { super(props); + this.state.languages: [] + this.state.armor: '', + this.state.numberOfShoes: '', } } class Animal extends NPC { constructor(props) { super(props); + this.state.claws: true, + this.state.magic: false } } class Plant extends NPC { constructor(props) { super(props); + this.state.medicinal: true, + this.state.poisonous: true, + this.state.edible: false, } } // * Humanoid -> Human, Elf, Orc class Human extends Humanoid { // Human props relative to roll of dice constructor(props) { super(props); + this.state.languages: ['common'] } } class Elf extends Humanoid { constructor(props) { super(props); + this.state.languages: ['common', 'elvish'] } } class Orc extends Humanoid { constructor(props) { super(props) + this.state.languages: ['orcish'] } } // * Animal -> Bear, Wolf class Bear extends Animal { constructor(props) { super(props) + this.state.height: {feet: 6, inches: 6} } } class Wolf extends Animal { constructor(props) { super(props) + this.state.packStatus: {alpha: false, beta: true, omega: false} } } // * Plant -> FleshEatingDaisy class FleshEatingDaisy { constructor(props) { super(props) + this.state.odor: {delightful: false, deadly: false, pernicious: true} } } From fe845d87bb04dd20b6adce9027b316f0fd947775 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 26 Jul 2017 12:50:33 -0400 Subject: [PATCH 152/523] =?UTF-8?q?cc13=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constructors/constructors.js | 79 +++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/constructors/constructors.js b/constructors/constructors.js index cf78000..81d1e63 100644 --- a/constructors/constructors.js +++ b/constructors/constructors.js @@ -26,74 +26,107 @@ class NPC { constructor(props) { this.state = { - name: '', + name: props, weapon: '', health: '', strength: '', - level: '', + _level: 1, // <--- private? Only the DM can establish characters above level 1 } } -} +}; // * NPC -> Humanoid, Animal, Plant class Humanoid extends NPC { constructor(props) { super(props); - this.state.languages: [] - this.state.armor: '', - this.state.numberOfShoes: '', + this.state.languages = []; + this.state.armor = ''; + this.state.numberOfShoes = ''; } -} +}; class Animal extends NPC { constructor(props) { super(props); - this.state.claws: true, - this.state.magic: false + this.state.claws = true; + this.state.magic = false; } } class Plant extends NPC { constructor(props) { super(props); - this.state.medicinal: true, - this.state.poisonous: true, - this.state.edible: false, + this.state.medicinal = true; + this.state.poisonous = true; + this.state.edible = false; } } // * Humanoid -> Human, Elf, Orc class Human extends Humanoid { // Human props relative to roll of dice constructor(props) { super(props); - this.state.languages: ['common'] + this.state.health = Math.floor(Math.random() * 100); + this.state.strength = Math.floor(Math.random() * 100); + this.state.languages = ['common']; } } class Elf extends Humanoid { constructor(props) { super(props); - this.state.languages: ['common', 'elvish'] + this.state.languages = ['common', 'elvish']; } } class Orc extends Humanoid { constructor(props) { - super(props) - this.state.languages: ['orcish'] + super(props); + this.state.languages = ['orcish']; } } // * Animal -> Bear, Wolf class Bear extends Animal { constructor(props) { - super(props) - this.state.height: {feet: 6, inches: 6} + super(props); + this.state.height = {feet: 6, inches: 6}; } } class Wolf extends Animal { constructor(props) { - super(props) - this.state.packStatus: {alpha: false, beta: true, omega: false} + super(props); + this.state.packStatus = {alpha: false, beta: true, omega: false}; } } // * Plant -> FleshEatingDaisy -class FleshEatingDaisy { +class FleshEatingDaisy extends Plant{ constructor(props) { - super(props) - this.state.odor: {delightful: false, deadly: false, pernicious: true} + super(props); + this.state.odor = {delightful: false, deadly: false, pernicious: true}; } } + +// TEST SUITE +const npc = new NPC('first'); +console.log(npc); + +const zarthonFleven = new Humanoid('Zarthon Fleven'); +console.log(zarthonFleven); + +const ladyBug = new Animal('Lady Bug'); +console.log(ladyBug); + +const sunFlower = new Plant('Sun Flower'); +console.log(sunFlower); + +const bob = new Human('Bob'); +console.log(bob); + +const velaria = new Elf('Velaria'); +console.log(velaria); + +const graarg = new Orc('Graarg'); +console.log(graarg); + +const paul = new Bear('Paul'); +console.log(paul); + +const simonLeBon = new Wolf('Simon Le Bon'); +console.log(simonLeBon); + +const foofie = new FleshEatingDaisy('Foofie the Flesh Eating Daisy'); +console.log(foofie); From 657aebdd4c70d409a4432a6eb6c4f884163cf381 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 26 Jul 2017 12:55:26 -0400 Subject: [PATCH 153/523] =?UTF-8?q?cc13=20constructors=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constructors/constructors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constructors/constructors.js b/constructors/constructors.js index 81d1e63..155f88b 100644 --- a/constructors/constructors.js +++ b/constructors/constructors.js @@ -70,7 +70,7 @@ class Human extends Humanoid { // Human props relative to roll of dice class Elf extends Humanoid { constructor(props) { super(props); - this.state.languages = ['common', 'elvish']; + this.state.languages.push('common', 'elvish'); // not sure which is a better way...? maybe an object instead w/fluent/literate/illiterate/rudimentary/etc? } } class Orc extends Humanoid { From 7298783126bc7a62429484a50bfa8fe5a329a1b3 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 26 Jul 2017 12:59:36 -0400 Subject: [PATCH 154/523] idem --- constructors/constructors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constructors/constructors.js b/constructors/constructors.js index 155f88b..06bb885 100644 --- a/constructors/constructors.js +++ b/constructors/constructors.js @@ -107,7 +107,7 @@ console.log(npc); const zarthonFleven = new Humanoid('Zarthon Fleven'); console.log(zarthonFleven); -const ladyBug = new Animal('Lady Bug'); +const ladyBug = new Animal('Sir Ladybug'); console.log(ladyBug); const sunFlower = new Plant('Sun Flower'); From 6d8d5c474a6891b4a2fa0bd73c848f8b556a2309 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 26 Jul 2017 13:03:51 -0400 Subject: [PATCH 155/523] idem --- constructors/constructors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constructors/constructors.js b/constructors/constructors.js index 06bb885..ca50a47 100644 --- a/constructors/constructors.js +++ b/constructors/constructors.js @@ -40,7 +40,7 @@ class Humanoid extends NPC { super(props); this.state.languages = []; this.state.armor = ''; - this.state.numberOfShoes = ''; + this.state.numberOfShoes = 2; } }; class Animal extends NPC { From 50ba7b9bfb05c8bf26c1d685b50da7605418a90e Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 26 Jul 2017 13:30:04 -0400 Subject: [PATCH 156/523] todo: edge cases --- operators/operators.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/operators/operators.js b/operators/operators.js index 9747d6d..0c2daff 100644 --- a/operators/operators.js +++ b/operators/operators.js @@ -5,6 +5,10 @@ * For division just drop the remainder. */ +// Edge cases: multiply by zero +// divide by zero +// negative numbers + const multiply = function(a, b) { const arr = new Array(b).fill(a); const product = arr.reduce((a, b) => a + b, 0); From 3bccae30b01cf7d87555e45af58da9dd55a0f0cc Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 26 Jul 2017 13:30:16 -0400 Subject: [PATCH 157/523] Tai's solution --- operators/Tai_solution.js | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 operators/Tai_solution.js diff --git a/operators/Tai_solution.js b/operators/Tai_solution.js new file mode 100644 index 0000000..6d0a7dd --- /dev/null +++ b/operators/Tai_solution.js @@ -0,0 +1,51 @@ +/* + * Implement three functions called multiply, divide, and modulo. + * These functions should multiply, divide, or return the remainder of two arguments. + * Now for the tricky part: you can only use the + and - operators to implement these functions. + * For division just drop the remainder. + */ + +const multiply = (x, y) => { + const absX = x < 0 ? 0 - x: x; + const absY = y < 0 ? 0 - y: y; + let product = 0; + for (let i = 0; i < absX; i++) product += absY; + if (x < 0 && y < 0) return product; + if (x < 0 || y < 0) return 0 - product; + return product; +}; + +const divide = (x, y) => { + if (y === 0) return NaN; + let absX = x < 0 ? 0 - x: x; + let absY = y < 0 ? 0 - y: y; + let quotient = 0; + while (absX > 0) { + absX -= absY; + if (absX >= 0) quotient += 1; + } + if (x < 0 && y < 0) return quotient; + if (x < 0 || y < 0) return 0 - quotient; + return quotient; +}; + +const modulo = (x, y) => { + if (y === 0) return NaN; + let absX = x < 0 ? 0 - x: x; + let absY = y < 0 ? 0 - y: y; + while (absX >= absY) absX -= absY; + if (x < 0 || y < 0) return 0 - absX; + return absX; +}; + +console.log(multiply(15, 10)); // 150 +console.log(multiply(15, 0)); // 0 +console.log(multiply(-15, 10)); // -150 +console.log(multiply(-15, -10)); // 150 +console.log(divide(15, 5)); // 3 +console.log(divide(15, 0)); // NaN +console.log(modulo(15, 0)); // NaN +console.log(modulo(15, 7)); // 1 +console.log(modulo(15, -7)); // -1 +console.log(modulo(-15, 7)); // -1 +console.log(modulo(-15, -7)); // 1 From 03705c83355ed64a29f813e89496ff9f749e53e7 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 26 Jul 2017 16:51:37 -0400 Subject: [PATCH 158/523] cc12 operators: edge cases wip --- operators/operators.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/operators/operators.js b/operators/operators.js index 0c2daff..6ec4e74 100644 --- a/operators/operators.js +++ b/operators/operators.js @@ -7,7 +7,7 @@ // Edge cases: multiply by zero // divide by zero -// negative numbers +// negative input numbers const multiply = function(a, b) { const arr = new Array(b).fill(a); @@ -36,11 +36,16 @@ const modulo = function(phi, psi) { // TEST SUITE // multiplication -console.log(multiply(2, 10)) // ---> 20 -console.log(multiply(1, 1)) // ---> 1 +console.log(multiply(2, 10)); // ---> 20 +console.log(multiply(1, 1)); // ---> 1 +console.log(multiply(21, 0)); +// console.log(multiply(21, -1)); +// console.log(multiply(-21, 1)); +// console.log(multiply(-21, -3)); + // division -console.log(divide(121, 11)) // ---> 11 remainder 0 -console.log(divide(123, 11)) // ---> 11 remainder 2 +console.log(divide(121, 11)); // ---> 11 remainder 0 +console.log(divide(123, 11)); // ---> 11 remainder 2 // modulo -console.log(modulo(15000, 11)) // ---> 7 -console.log(modulo(123, 11)) // ---> 2 +console.log(modulo(15000, 11)); // ---> 7 +console.log(modulo(123, 11)); // ---> 2 From c5012ebcf18df899423904caa0ff26a68257d931 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 27 Jul 2017 12:20:02 -0400 Subject: [PATCH 159/523] basic stack class --- queueStack/queueStack.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/queueStack/queueStack.js b/queueStack/queueStack.js index 5a05207..9690a9d 100644 --- a/queueStack/queueStack.js +++ b/queueStack/queueStack.js @@ -2,3 +2,29 @@ * Write a stack class. Once you're done, * implement a queue using two stacks. */ + + class PhatStack { + constructor() { + this.storage = []; + } + get size() { return this.storage.length } + add(anItem) { return this.storage.push(anItem) } + remove() { return this.storage.pop() } + get show() { return this.storage } + } + + // TEST SUITE + const test = new PhatStack(); // a new instance of the class + console.log(test); // ---> PhatStack { storage: [] } + console.log(test.size); // ---> 0 ...or, without "get" ---> [Function: size] + // console.log(test.size()); // ---> TypeError ...or, without "get" ---> 0 + test.add('stuff'); // add an item + console.log(test.size); // ---> 1 + console.log(test.show); // ---> [ 'stuff' ] + console.log(test.storage); // ---> [ 'stuff' ] SAME + console.log(test.remove()); // ---> stuff (returns the removed item) + console.log(test.size); // ---> 0 + console.log(test.storage); // ---> [] + console.log(test.remove()); // ---> undefined (nothing to remove from an empty storage array) + console.log(test.size); // ---> 0 + console.log(test.storage); // ---> [] From 18d01fba62dcc0a4413cd4ffb8211d872068c869 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 27 Jul 2017 12:24:06 -0400 Subject: [PATCH 160/523] implicit returns --- queueStack/queueStack.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/queueStack/queueStack.js b/queueStack/queueStack.js index 9690a9d..6fde321 100644 --- a/queueStack/queueStack.js +++ b/queueStack/queueStack.js @@ -7,10 +7,10 @@ constructor() { this.storage = []; } - get size() { return this.storage.length } - add(anItem) { return this.storage.push(anItem) } - remove() { return this.storage.pop() } - get show() { return this.storage } + get size() { this.storage.length } + add(anItem) { this.storage.push(anItem) } + remove() { this.storage.pop() } + get show() { this.storage } } // TEST SUITE From bf3ed3d085cff8e441d4f2c78a9be77cb0b3b76d Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 27 Jul 2017 12:31:34 -0400 Subject: [PATCH 161/523] not implicit return --- queueStack/queueStack.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/queueStack/queueStack.js b/queueStack/queueStack.js index 6fde321..cc1fccf 100644 --- a/queueStack/queueStack.js +++ b/queueStack/queueStack.js @@ -7,10 +7,11 @@ constructor() { this.storage = []; } - get size() { this.storage.length } - add(anItem) { this.storage.push(anItem) } - remove() { this.storage.pop() } - get show() { this.storage } + get size() { return this.storage.length } + add(anItem) { return this.storage.push(anItem) } + // set add(anItem) { this.storage.push(anItem) } + remove() { return this.storage.pop() } + get show() { return this.storage } } // TEST SUITE @@ -18,7 +19,8 @@ console.log(test); // ---> PhatStack { storage: [] } console.log(test.size); // ---> 0 ...or, without "get" ---> [Function: size] // console.log(test.size()); // ---> TypeError ...or, without "get" ---> 0 - test.add('stuff'); // add an item + test.add('stuff'); // add an item without setter + // test.add = 'stuff'; // WHY DOES THIS KILL MY get METHODS????????????????????? console.log(test.size); // ---> 1 console.log(test.show); // ---> [ 'stuff' ] console.log(test.storage); // ---> [ 'stuff' ] SAME From ac4f44bf8ed86de613b0a464ca9039850143c806 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 27 Jul 2017 12:35:27 -0400 Subject: [PATCH 162/523] =?UTF-8?q?stack=20class=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- queueStack/queueStack.js | 55 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/queueStack/queueStack.js b/queueStack/queueStack.js index cc1fccf..8232a08 100644 --- a/queueStack/queueStack.js +++ b/queueStack/queueStack.js @@ -3,30 +3,33 @@ * implement a queue using two stacks. */ - class PhatStack { - constructor() { - this.storage = []; - } - get size() { return this.storage.length } - add(anItem) { return this.storage.push(anItem) } - // set add(anItem) { this.storage.push(anItem) } - remove() { return this.storage.pop() } - get show() { return this.storage } - } +class PhatStack { + constructor() { + this.storage = []; + } + get size() { return this.storage.length } + set add(anItem) { this.storage.push(anItem) } + remove() { return this.storage.pop() } + get show() { return this.storage } +} - // TEST SUITE - const test = new PhatStack(); // a new instance of the class - console.log(test); // ---> PhatStack { storage: [] } - console.log(test.size); // ---> 0 ...or, without "get" ---> [Function: size] - // console.log(test.size()); // ---> TypeError ...or, without "get" ---> 0 - test.add('stuff'); // add an item without setter - // test.add = 'stuff'; // WHY DOES THIS KILL MY get METHODS????????????????????? - console.log(test.size); // ---> 1 - console.log(test.show); // ---> [ 'stuff' ] - console.log(test.storage); // ---> [ 'stuff' ] SAME - console.log(test.remove()); // ---> stuff (returns the removed item) - console.log(test.size); // ---> 0 - console.log(test.storage); // ---> [] - console.log(test.remove()); // ---> undefined (nothing to remove from an empty storage array) - console.log(test.size); // ---> 0 - console.log(test.storage); // ---> [] +// TEST SUITE +const test = new PhatStack(); // a new instance of the class +console.log(test); // ---> PhatStack { storage: [] } +console.log(test.size); // ---> 0 ...or, without "get" ---> [Function: size] +// console.log(test.size()); // ---> TypeError ...or, without "get" ---> 0 +// test.add('stuff'); // add an item without setter +test.add = 'stuff'; // +console.log(test.size); // ---> 1 +console.log(test.show); // ---> [ 'stuff' ] +console.log(test.storage); // ---> [ 'stuff' ] SAME +console.log(test.remove()); // ---> stuff (returns the removed item) +console.log(test.size); // ---> 0 +console.log(test.storage); // ---> [] +console.log(test.remove()); // ---> undefined (nothing to remove from an empty storage array) +console.log(test.size); // ---> 0 +console.log(test.storage); // ---> [] +test.add = 'more stuff' +test.add = 'even more stuff' +test.add = 'some more AMAZING stuff' +console.log(test.show); // ---> [ 'more stuff', 'even more stuff', 'some more AMAZING stuff' ] From 4ecb635a9132fc9006224932e303dae2c10966f7 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 27 Jul 2017 12:58:39 -0400 Subject: [PATCH 163/523] basic queue --- queueStack/queueStack.js | 60 ++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/queueStack/queueStack.js b/queueStack/queueStack.js index 8232a08..4f1dcea 100644 --- a/queueStack/queueStack.js +++ b/queueStack/queueStack.js @@ -1,8 +1,8 @@ /** * Write a stack class. Once you're done, * implement a queue using two stacks. - */ - + Stack=(First In Last Out) & Queue=(First In First Out) +*/ class PhatStack { constructor() { this.storage = []; @@ -13,23 +13,41 @@ class PhatStack { get show() { return this.storage } } +class TwoStackQueueKungFu extends PhatStack { + constructor() { + super();// dooper + } + enqueue(something) {this.add = [something]} + dequeque() {return this.storage.shift();} // HOW TO IMPLEMENT WITH TWO STACKS??????? +} + // TEST SUITE -const test = new PhatStack(); // a new instance of the class -console.log(test); // ---> PhatStack { storage: [] } -console.log(test.size); // ---> 0 ...or, without "get" ---> [Function: size] -// console.log(test.size()); // ---> TypeError ...or, without "get" ---> 0 -// test.add('stuff'); // add an item without setter -test.add = 'stuff'; // -console.log(test.size); // ---> 1 -console.log(test.show); // ---> [ 'stuff' ] -console.log(test.storage); // ---> [ 'stuff' ] SAME -console.log(test.remove()); // ---> stuff (returns the removed item) -console.log(test.size); // ---> 0 -console.log(test.storage); // ---> [] -console.log(test.remove()); // ---> undefined (nothing to remove from an empty storage array) -console.log(test.size); // ---> 0 -console.log(test.storage); // ---> [] -test.add = 'more stuff' -test.add = 'even more stuff' -test.add = 'some more AMAZING stuff' -console.log(test.show); // ---> [ 'more stuff', 'even more stuff', 'some more AMAZING stuff' ] +const testq = new TwoStackQueueKungFu(); +console.log(testq); // ---> TwoStackQueueKungFu { storage: [] } +console.log(testq.size) // ---> 0 (inherited method) +console.log(testq.show) // ---> [] (inherited method) +testq.add = 'cute' +console.log(testq.size) // ---> 1 +console.log(testq.show) // ---> [ 'cute' ] + + +// // STACK TEST SUITE +// const test = new PhatStack(); // a new instance of the class +// console.log(test); // ---> PhatStack { storage: [] } +// console.log(test.size); // ---> 0 ...or, without "get" ---> [Function: size] +// // console.log(test.size()); // ---> TypeError ...or, without "get" ---> 0 +// // test.add('stuff'); // add an item without setter +// test.add = 'stuff'; +// console.log(test.size); // ---> 1 +// console.log(test.show); // ---> [ 'stuff' ] +// console.log(test.storage); // ---> [ 'stuff' ] SAME +// console.log(test.remove()); // ---> stuff (returns the removed item) +// console.log(test.size); // ---> 0 +// console.log(test.show); // ---> [] +// console.log(test.remove()); // ---> undefined (nothing to remove from an empty storage array) +// console.log(test.size); // ---> 0 +// console.log(test.show); // ---> [] +// test.add = 'more stuff' +// test.add = 'even more stuff' +// test.add = 'some more AMAZING stuff' +// console.log(test.show); // ---> [ 'more stuff', 'even more stuff', 'some more AMAZING stuff' ] From fa31df6c5f1be2c2096a94d540d72a8009badcd6 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 01:44:02 -0400 Subject: [PATCH 164/523] queue inhertance --- queueStack/queueStack.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/queueStack/queueStack.js b/queueStack/queueStack.js index 4f1dcea..f856bf8 100644 --- a/queueStack/queueStack.js +++ b/queueStack/queueStack.js @@ -21,15 +21,30 @@ class TwoStackQueueKungFu extends PhatStack { dequeque() {return this.storage.shift();} // HOW TO IMPLEMENT WITH TWO STACKS??????? } + + + + + + + + + + + // TEST SUITE const testq = new TwoStackQueueKungFu(); console.log(testq); // ---> TwoStackQueueKungFu { storage: [] } -console.log(testq.size) // ---> 0 (inherited method) -console.log(testq.show) // ---> [] (inherited method) -testq.add = 'cute' -console.log(testq.size) // ---> 1 -console.log(testq.show) // ---> [ 'cute' ] - +console.log(testq.size); // ---> 0 (inherited method) +console.log(testq.show); // ---> [] (inherited method) +testq.add = 'first'; +console.log(testq.size); // ---> 1 +console.log(testq.show); // ---> [ 'first' ] +testq.add = 'in'; +testq.add = 'last'; +testq.add = 'out'; +console.log(testq); +console.log(testq.show); // ---> [ 'first', 'in', 'last', 'out' ] // // STACK TEST SUITE // const test = new PhatStack(); // a new instance of the class From 199b3f0cbe8904eb2638fba92b2233ce78522584 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 01:55:05 -0400 Subject: [PATCH 165/523] hmmmm --- queueStack/queueStack.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/queueStack/queueStack.js b/queueStack/queueStack.js index f856bf8..59b10b0 100644 --- a/queueStack/queueStack.js +++ b/queueStack/queueStack.js @@ -16,8 +16,9 @@ class PhatStack { class TwoStackQueueKungFu extends PhatStack { constructor() { super();// dooper + } - enqueue(something) {this.add = [something]} + enqueue(something) {this.add(something)} dequeque() {return this.storage.shift();} // HOW TO IMPLEMENT WITH TWO STACKS??????? } @@ -37,13 +38,13 @@ const testq = new TwoStackQueueKungFu(); console.log(testq); // ---> TwoStackQueueKungFu { storage: [] } console.log(testq.size); // ---> 0 (inherited method) console.log(testq.show); // ---> [] (inherited method) -testq.add = 'first'; +testq.enqueue = 'first'; console.log(testq.size); // ---> 1 console.log(testq.show); // ---> [ 'first' ] -testq.add = 'in'; -testq.add = 'last'; -testq.add = 'out'; -console.log(testq); +testq.enqueue = 'in'; +testq.enqueue = 'last'; +testq.enqueue = 'out'; +console.log(testq); console.log(testq.show); // ---> [ 'first', 'in', 'last', 'out' ] // // STACK TEST SUITE From 531c4b3d406876c943b4c7c8920bed6bc863b147 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 02:02:27 -0400 Subject: [PATCH 166/523] i don't think inheritance is the way to go here... start over --- queueStack/queueStack.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/queueStack/queueStack.js b/queueStack/queueStack.js index 59b10b0..f2b3b9c 100644 --- a/queueStack/queueStack.js +++ b/queueStack/queueStack.js @@ -16,10 +16,9 @@ class PhatStack { class TwoStackQueueKungFu extends PhatStack { constructor() { super();// dooper - } - enqueue(something) {this.add(something)} - dequeque() {return this.storage.shift();} // HOW TO IMPLEMENT WITH TWO STACKS??????? + enqueue(something) {this.add = [something]} + dequeue() {return this.storage.shift();} // HOW TO IMPLEMENT WITH TWO STACKS??????? } @@ -38,14 +37,16 @@ const testq = new TwoStackQueueKungFu(); console.log(testq); // ---> TwoStackQueueKungFu { storage: [] } console.log(testq.size); // ---> 0 (inherited method) console.log(testq.show); // ---> [] (inherited method) -testq.enqueue = 'first'; +testq.add = 'first'; console.log(testq.size); // ---> 1 console.log(testq.show); // ---> [ 'first' ] -testq.enqueue = 'in'; -testq.enqueue = 'last'; -testq.enqueue = 'out'; +testq.add = 'in'; +testq.add = 'last'; +testq.add = 'out'; console.log(testq); console.log(testq.show); // ---> [ 'first', 'in', 'last', 'out' ] +testq.dequeue(); +console.log(testq.show); // ---> [ 'first', 'in', 'last', 'out' ] // // STACK TEST SUITE // const test = new PhatStack(); // a new instance of the class From e9f83e1cdba9237f8d95fcde5d9530d42efcc3b3 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 02:25:39 -0400 Subject: [PATCH 167/523] =?UTF-8?q?lifo=20>>>=20fifo=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- queueStack/queueStack.js | 50 ++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/queueStack/queueStack.js b/queueStack/queueStack.js index f2b3b9c..5c75c3f 100644 --- a/queueStack/queueStack.js +++ b/queueStack/queueStack.js @@ -1,7 +1,7 @@ /** * Write a stack class. Once you're done, * implement a queue using two stacks. - Stack=(First In Last Out) & Queue=(First In First Out) + Stack=(Last In First Out) & Queue=(First In First Out) */ class PhatStack { constructor() { @@ -13,40 +13,36 @@ class PhatStack { get show() { return this.storage } } -class TwoStackQueueKungFu extends PhatStack { +class TwoStackQueueKungFu { constructor() { - super();// dooper + this.lifo = new PhatStack(); + this.fifo = new PhatStack(); } - enqueue(something) {this.add = [something]} - dequeue() {return this.storage.shift();} // HOW TO IMPLEMENT WITH TWO STACKS??????? -} - - - - - - - - - - + set enqueue(something) {this.lifo.add = something} + dequeue() { + console.log(this.fifo.size); + if (this.fifo.size === 0) { + while (this.lifo.size) { + this.fifo.storage.push(this.lifo.storage.pop()); + console.log(this.fifo.storage); + } + } + return this.fifo; + }; +} // TEST SUITE const testq = new TwoStackQueueKungFu(); console.log(testq); // ---> TwoStackQueueKungFu { storage: [] } -console.log(testq.size); // ---> 0 (inherited method) -console.log(testq.show); // ---> [] (inherited method) -testq.add = 'first'; -console.log(testq.size); // ---> 1 -console.log(testq.show); // ---> [ 'first' ] -testq.add = 'in'; -testq.add = 'last'; -testq.add = 'out'; -console.log(testq); -console.log(testq.show); // ---> [ 'first', 'in', 'last', 'out' ] +testq.enqueue = 'first'; +testq.enqueue = 'in'; +testq.enqueue = 'last'; +testq.enqueue = 'out'; +console.log(testq); // ---> [ 'first', 'in', 'last', 'out' ] testq.dequeue(); -console.log(testq.show); // ---> [ 'first', 'in', 'last', 'out' ] +console.log(testq); // ---> [ 'first', 'in', 'last', 'out' ] + // // STACK TEST SUITE // const test = new PhatStack(); // a new instance of the class From ae9c7ffa59270fd77b77f51ca4588e1d3112cccf Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 02:48:13 -0400 Subject: [PATCH 168/523] =?UTF-8?q?cc14=20queueStack=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- queueStack/queueStack.js | 45 ++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/queueStack/queueStack.js b/queueStack/queueStack.js index 5c75c3f..a430c08 100644 --- a/queueStack/queueStack.js +++ b/queueStack/queueStack.js @@ -15,33 +15,52 @@ class PhatStack { class TwoStackQueueKungFu { constructor() { - this.lifo = new PhatStack(); - this.fifo = new PhatStack(); + this.input = new PhatStack(); + this.output = new PhatStack(); } - set enqueue(something) {this.lifo.add = something} + set enqueue(something) {this.input.add = something} dequeue() { - console.log(this.fifo.size); - if (this.fifo.size === 0) { - while (this.lifo.size) { - this.fifo.storage.push(this.lifo.storage.pop()); - console.log(this.fifo.storage); + // console.log(this.output.size); + if (this.output.size === 0) { + while (this.input.size) { + this.output.storage.push(this.input.storage.pop()); + // console.log(this.output.storage); } } - return this.fifo; + console.log(testq.output.storage); + return this.output.storage.pop(); }; + + get showOutput() { return this.output.storage } } -// TEST SUITE +// QUEUE W/2 STACKS TEST SUITE const testq = new TwoStackQueueKungFu(); console.log(testq); // ---> TwoStackQueueKungFu { storage: [] } +testq.enqueue = 'not'; testq.enqueue = 'first'; testq.enqueue = 'in'; testq.enqueue = 'last'; testq.enqueue = 'out'; -console.log(testq); // ---> [ 'first', 'in', 'last', 'out' ] -testq.dequeue(); -console.log(testq); // ---> [ 'first', 'in', 'last', 'out' ] +console.log(testq); // ---> [ 'not', 'first', 'in', 'last', 'out' ] +// console.log(testq.show); +console.log(testq.dequeue()); // ---> not +console.log(testq.dequeue()); // ---> first +console.log(testq.dequeue()); // ---> in +console.log(testq.dequeue()); // ---> last +console.log(testq.dequeue()); // ---> out +console.log(testq); // ---> input and output: [] +testq.enqueue = 'first'; +testq.enqueue = 'in'; +testq.enqueue = 'first'; +testq.enqueue = 'out'; +console.log(testq); // ---> [ 'first', 'in', 'first', 'out' ] +console.log(testq.dequeue()); // ---> first +console.log(testq.dequeue()); // ---> in +console.log(testq.dequeue()); // ---> first +console.log(testq.dequeue()); // ---> out +console.log(testq); // ---> // // STACK TEST SUITE From 2f6dde883e44c71c753347bb13194a2507143056 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 12:19:20 -0400 Subject: [PATCH 169/523] v1 --- bubbleSort/bubbleSort.js | 44 ++++++++++++++++++---------------------- bubbleSort/readme.md | 22 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 bubbleSort/readme.md diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index 69211d2..98d7ec3 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -1,26 +1,22 @@ -/* - * Bubble sort is the most basic sorting algorithm. - * It compares the first element of an array with the second element. - * If the first element is greater than the second element then it swaps them. - * Then it compares the second and third elements and swaps them if the second is larger. - * Then it compares the third and fourth elements and does the same. - * This continues and the the larger elements begin to "bubble" towards the end. - * The loop then restarts and repeats this process until it makes a clean pass - * without performing any swaps. - * - * Implement a function that takes an array and sorts it using this technique. - * Don't use JavaScript's built-in sorting function (Array.prototype.sort). - * - * What's the time complexity of your algorithm? Are there ways you can improve it? - * -*/ - -/* - * Example: - * bubbleSort([2, 1, 3]); // returns [1, 2, 3] - * -*/ - const bubbleSort = (arr) => { - //code here + for (let i = 0; i < arr.length; i++) { + let modify = 0; + let current = arr[i]; + let next = arr[i + 1]; + while (next !== undefined) { + console.log(`BEFORE: current index value: ${current}; next index: ${next}`); + if (next < current) { + arr[i] = next; + arr[i = 1] = current; + console.log(`AFTER: current index value: ${current}; next index: ${next}`); + modify++; + } + if (modify !== 0) { + // bubbleSort(arr); + console.log('more to sort', arr) + } + } + } return arr; }; + +console.log(bubbleSort([ 2, 1, 3 ])) diff --git a/bubbleSort/readme.md b/bubbleSort/readme.md new file mode 100644 index 0000000..3da32ec --- /dev/null +++ b/bubbleSort/readme.md @@ -0,0 +1,22 @@ +/* + * Bubble sort is the most basic sorting algorithm. + * It compares the first element of an array with the second element. + * If the first element is greater than the second element then it swaps them. + * Then it compares the second and third elements and swaps them if the second is larger. + * Then it compares the third and fourth elements and does the same. + * This continues and the the larger elements begin to "bubble" towards the end. + * The loop then restarts and repeats this process until it makes a clean pass + * without performing any swaps. + * + * Implement a function that takes an array and sorts it using this technique. + * Don't use JavaScript's built-in sorting function (Array.prototype.sort). + * + * What's the time complexity of your algorithm? Are there ways you can improve it? + * +*/ + +/* + * Example: + * bubbleSort([2, 1, 3]); // returns [1, 2, 3] + * +*/ From 2d92088670cc99561fa665839af1d491a81e4945 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 12:22:41 -0400 Subject: [PATCH 170/523] ofc this dsnt wrk --- bubbleSort/bubbleSort.js | 49 +++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index 98d7ec3..1c4fe83 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -1,22 +1,35 @@ const bubbleSort = (arr) => { - for (let i = 0; i < arr.length; i++) { - let modify = 0; - let current = arr[i]; - let next = arr[i + 1]; - while (next !== undefined) { - console.log(`BEFORE: current index value: ${current}; next index: ${next}`); - if (next < current) { - arr[i] = next; - arr[i = 1] = current; - console.log(`AFTER: current index value: ${current}; next index: ${next}`); - modify++; - } - if (modify !== 0) { - // bubbleSort(arr); - console.log('more to sort', arr) - } - } - } return arr; + // compare first array element to second + if (arr[0] > arr[1]) { + arr[0] = arr[1]; + arr[1] = arr[0]; + } + return arr; }; + console.log(bubbleSort([ 2, 1, 3 ])) + + + + +// const bubbleSort = (arr) => { +// for (let i = 0; i < arr.length; i++) { +// let modify = 0; +// let current = arr[i]; +// let next = arr[i + 1]; +// while (next !== undefined) { +// console.log(`BEFORE: current index value: ${current}; next index: ${next}`); +// if (next < current) { +// arr[i] = next; +// arr[i = 1] = current; +// console.log(`AFTER: current index value: ${current}; next index: ${next}`); +// modify++; +// } +// if (modify !== 0) { +// // bubbleSort(arr); +// console.log('more to sort', arr) +// } +// } +// } return arr; +// }; From 8d7c8622b921afa7875c23fabe592a20ed9c7fde Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 12:24:21 -0400 Subject: [PATCH 171/523] compare 1st & 2nd, swap if 1st > 2nd --- bubbleSort/bubbleSort.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index 1c4fe83..1c98704 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -1,8 +1,10 @@ const bubbleSort = (arr) => { // compare first array element to second - if (arr[0] > arr[1]) { - arr[0] = arr[1]; - arr[1] = arr[0]; + let first = arr[0]; + let second = arr[1]; + if (first > second) { + arr[0] = second; + arr[1] = first; } return arr; }; From 2930e2803e4a4646f2090d4f47fa16ed1784ae6e Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 12:24:50 -0400 Subject: [PATCH 172/523] idem --- bubbleSort/bubbleSort.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index 1c98704..f19fb36 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -2,6 +2,7 @@ const bubbleSort = (arr) => { // compare first array element to second let first = arr[0]; let second = arr[1]; + // swap if 1st is greater than 2nd if (first > second) { arr[0] = second; arr[1] = first; From fae85e76a35230e082d2e20d3e64701cb69de4b0 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 12:30:39 -0400 Subject: [PATCH 173/523] basic swap --- bubbleSort/bubbleSort.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index f19fb36..dcd5e83 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -1,18 +1,21 @@ const bubbleSort = (arr) => { - // compare first array element to second - let first = arr[0]; - let second = arr[1]; - // swap if 1st is greater than 2nd - if (first > second) { - arr[0] = second; - arr[1] = first; + for (let i = 0; i < arr.length; i++) { + // compare first array element to second + let first = arr[i]; + let second = arr[i + 1]; + // swap if 1st is greater than 2nd + if (first > second) { + arr[i] = second; + arr[i + 1] = first; + } + console.log(arr); } return arr; }; -console.log(bubbleSort([ 2, 1, 3 ])) - +console.log('TEST01: ', bubbleSort([ 2, 1, 3 ])) // ---> [ 1, 2, 3 ] +console.log('TEST02: ', bubbleSort([ 2, 1, 5, 4, 3 ])) // ---> From d0cf4037c22e2b03eb606772109c16d034d62121 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 12:34:43 -0400 Subject: [PATCH 174/523] mod var tracks sorting iters --- bubbleSort/bubbleSort.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index dcd5e83..5903f57 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -1,4 +1,7 @@ const bubbleSort = (arr) => { + // mod var to track if sorting done + let modify = 0; + // compare first/second pairs per each index - maybe current/next is a better name? for (let i = 0; i < arr.length; i++) { // compare first array element to second let first = arr[i]; @@ -7,8 +10,9 @@ const bubbleSort = (arr) => { if (first > second) { arr[i] = second; arr[i + 1] = first; + modify++; } - console.log(arr); + console.log(arr, modify); } return arr; }; From f9ce810f108c444469208df7b6acd1afb56dfb8f Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 12:37:37 -0400 Subject: [PATCH 175/523] =?UTF-8?q?cc15=20bubbleSort=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bubbleSort/bubbleSort.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index 5903f57..2b745aa 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -12,15 +12,18 @@ const bubbleSort = (arr) => { arr[i + 1] = first; modify++; } - console.log(arr, modify); + // console.log(arr, modify); + if (modify !== 0) { + bubbleSort(arr) + } } return arr; }; console.log('TEST01: ', bubbleSort([ 2, 1, 3 ])) // ---> [ 1, 2, 3 ] -console.log('TEST02: ', bubbleSort([ 2, 1, 5, 4, 3 ])) // ---> - +console.log('TEST02: ', bubbleSort([ 2, 1, 5, 4, 3 ])) // ---> [ 1, 2, 3, 4, 5 ] +console.log('TEST03: ', bubbleSort([ 99, 34, 87, 135, 8, 3, 7, 99, 101, 102345, 3657, 2, 1, 5, 4, 3 ])) // ---> [ 1, 2, 3, 4, 5 ] // const bubbleSort = (arr) => { From 711d9641511365208bd41b918ee94a8975c9b371 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 12:41:44 -0400 Subject: [PATCH 176/523] =?UTF-8?q?cc15=20bubbleSort=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bubbleSort/bubbleSort.js | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index 2b745aa..5046db6 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -24,25 +24,3 @@ const bubbleSort = (arr) => { console.log('TEST01: ', bubbleSort([ 2, 1, 3 ])) // ---> [ 1, 2, 3 ] console.log('TEST02: ', bubbleSort([ 2, 1, 5, 4, 3 ])) // ---> [ 1, 2, 3, 4, 5 ] console.log('TEST03: ', bubbleSort([ 99, 34, 87, 135, 8, 3, 7, 99, 101, 102345, 3657, 2, 1, 5, 4, 3 ])) // ---> [ 1, 2, 3, 4, 5 ] - - -// const bubbleSort = (arr) => { -// for (let i = 0; i < arr.length; i++) { -// let modify = 0; -// let current = arr[i]; -// let next = arr[i + 1]; -// while (next !== undefined) { -// console.log(`BEFORE: current index value: ${current}; next index: ${next}`); -// if (next < current) { -// arr[i] = next; -// arr[i = 1] = current; -// console.log(`AFTER: current index value: ${current}; next index: ${next}`); -// modify++; -// } -// if (modify !== 0) { -// // bubbleSort(arr); -// console.log('more to sort', arr) -// } -// } -// } return arr; -// }; From e1e7b71c7f919c208463b4d0dcd40399383c670d Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 28 Jul 2017 14:26:20 -0400 Subject: [PATCH 177/523] queueStack review --- queueStack/queueStack.js | 61 +++++++++++++++++++------------------- queueStack/solution_Tai.js | 55 ++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 30 deletions(-) create mode 100644 queueStack/solution_Tai.js diff --git a/queueStack/queueStack.js b/queueStack/queueStack.js index a430c08..ab39e72 100644 --- a/queueStack/queueStack.js +++ b/queueStack/queueStack.js @@ -8,7 +8,7 @@ class PhatStack { this.storage = []; } get size() { return this.storage.length } - set add(anItem) { this.storage.push(anItem) } + set add(anItem) { this.storage.push(anItem) } // <---------- USING THE SETTER remove() { return this.storage.pop() } get show() { return this.storage } } @@ -21,11 +21,12 @@ class TwoStackQueueKungFu { set enqueue(something) {this.input.add = something} dequeue() { - // console.log(this.output.size); if (this.output.size === 0) { while (this.input.size) { - this.output.storage.push(this.input.storage.pop()); - // console.log(this.output.storage); + this.output.storage.push(this.input.storage.pop()); // <---- THIS WORKS + // // WHY DOES CALLING THE PhatStack Setter Method NOT WORK? ////////// + // // Error msg: "this.output.add is not a function" + // this.output.add(this.input.remove()); // <--- Setter method syntax } } console.log(testq.output.storage); @@ -35,32 +36,32 @@ class TwoStackQueueKungFu { get showOutput() { return this.output.storage } } -// QUEUE W/2 STACKS TEST SUITE -const testq = new TwoStackQueueKungFu(); -console.log(testq); // ---> TwoStackQueueKungFu { storage: [] } -testq.enqueue = 'not'; -testq.enqueue = 'first'; -testq.enqueue = 'in'; -testq.enqueue = 'last'; -testq.enqueue = 'out'; -console.log(testq); // ---> [ 'not', 'first', 'in', 'last', 'out' ] -// console.log(testq.show); -console.log(testq.dequeue()); // ---> not -console.log(testq.dequeue()); // ---> first -console.log(testq.dequeue()); // ---> in -console.log(testq.dequeue()); // ---> last -console.log(testq.dequeue()); // ---> out -console.log(testq); // ---> input and output: [] -testq.enqueue = 'first'; -testq.enqueue = 'in'; -testq.enqueue = 'first'; -testq.enqueue = 'out'; -console.log(testq); // ---> [ 'first', 'in', 'first', 'out' ] -console.log(testq.dequeue()); // ---> first -console.log(testq.dequeue()); // ---> in -console.log(testq.dequeue()); // ---> first -console.log(testq.dequeue()); // ---> out -console.log(testq); // ---> +// // QUEUE W/2 STACKS TEST SUITE +// const testq = new TwoStackQueueKungFu(); +// console.log(testq); // ---> TwoStackQueueKungFu { storage: [] } +// testq.enqueue = 'not'; +// testq.enqueue = 'first'; +// testq.enqueue = 'in'; +// testq.enqueue = 'last'; +// testq.enqueue = 'out'; +// console.log(testq); // ---> [ 'not', 'first', 'in', 'last', 'out' ] +// // console.log(testq.show); +// console.log(testq.dequeue()); // ---> not +// console.log(testq.dequeue()); // ---> first +// console.log(testq.dequeue()); // ---> in +// console.log(testq.dequeue()); // ---> last +// console.log(testq.dequeue()); // ---> out +// console.log(testq); // ---> input and output: [] +// testq.enqueue = 'first'; +// testq.enqueue = 'in'; +// testq.enqueue = 'first'; +// testq.enqueue = 'out'; +// console.log(testq); // ---> [ 'first', 'in', 'first', 'out' ] +// console.log(testq.dequeue()); // ---> first +// console.log(testq.dequeue()); // ---> in +// console.log(testq.dequeue()); // ---> first +// console.log(testq.dequeue()); // ---> out +// console.log(testq); // ---> // // STACK TEST SUITE diff --git a/queueStack/solution_Tai.js b/queueStack/solution_Tai.js new file mode 100644 index 0000000..e31c9dd --- /dev/null +++ b/queueStack/solution_Tai.js @@ -0,0 +1,55 @@ +/** + * Write a stack class. Once you're done, + * implement a queue using two stacks. + */ + +class Stack { + constructor() { + this.storage = []; + } + + add(item) { + this.storage.push(item); + } + + remove() { + if (this.storage.length === 0) return null; + return this.storage.pop(); + } + + get length() { + return this.storage.length; + } +} + +class Queue { + constructor() { + this.stack1 = new Stack(); + this.stack2 = new Stack(); + } + enqueue(item) { + this.stack1.add(item); + } + + dequeue() { + if (this.stack2.length === 0) { + const length = this.stack1.length; + for (let i = 0; i < length; i++) { + this.stack2.add(this.stack1.remove()); + } + } + return this.stack2.remove(); + } +} + +const queue = new Queue(); + +queue.enqueue(1); +queue.enqueue(2); +queue.enqueue(3); +const val1 = queue.dequeue(); +const val2 = queue.dequeue(); +queue.enqueue(4); +const val3 = queue.dequeue(); +const val4 = queue.dequeue(); +console.log(val1, val2, val3, val4); From ef9a440f3893def9f0bb760bc107fec17df4bb0b Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 29 Jul 2017 19:23:04 -0400 Subject: [PATCH 178/523] =?UTF-8?q?cc15=20-=20bubbleSort=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bubbleSort/bubbleSort.js | 61 +++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index 5046db6..6024d22 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -1,26 +1,49 @@ -const bubbleSort = (arr) => { - // mod var to track if sorting done - let modify = 0; - // compare first/second pairs per each index - maybe current/next is a better name? +// Code Challenge # 15 + +const bubbleSort = (arr, mod = 0) => { + + // compare (current/next) second pairs per each index for (let i = 0; i < arr.length; i++) { - // compare first array element to second - let first = arr[i]; - let second = arr[i + 1]; - // swap if 1st is greater than 2nd - if (first > second) { - arr[i] = second; - arr[i + 1] = first; + // counter to track if sorting is done + let modify = mod; + let current = arr[i]; + let next = arr[i + 1]; + + // if current is greater than next, swap & increment modification counter + // else, reset modification counter to zero to prevent recursive call + if (current > next) { + arr[i] = next; + arr[i + 1] = current; modify++; - } - // console.log(arr, modify); + } else modify = 0; + + // if list not sorted, if (modify !== 0) { - bubbleSort(arr) + // // UNCOMMENT TO CONSOLE.LOG() EACH PASS + // if (modify > 9) { + // console.log(`Sorting pass #${modify}: ${arr}`); + // } else { + // console.log(`Sorting pass #${modify}: ${arr}`); + // } + + // ...then recursively call function until modify count is 0 + bubbleSort(arr, modify) } - } + }; + + // return sorted array return arr; }; - -console.log('TEST01: ', bubbleSort([ 2, 1, 3 ])) // ---> [ 1, 2, 3 ] -console.log('TEST02: ', bubbleSort([ 2, 1, 5, 4, 3 ])) // ---> [ 1, 2, 3, 4, 5 ] -console.log('TEST03: ', bubbleSort([ 99, 34, 87, 135, 8, 3, 7, 99, 101, 102345, 3657, 2, 1, 5, 4, 3 ])) // ---> [ 1, 2, 3, 4, 5 ] +const test1 = [ 2, 1, 3 ]; +console.log(`TEST #1 UNSORTED: ${test1}`); +console.log(`TEST #1 SORTED: ${bubbleSort(test1)}\n`); +// ---> [ 1, 2, 3 ] +const test2 = [ 3, 2, 1, 3, 1, 5, 4, 3 ]; +console.log(`TEST #2 UNSORTED: ${test2}`); +console.log(`TEST #2 SORTED: ${bubbleSort(test2)}\n`); +// ---> [ 1, 1, 2, 3, 3, 3, 4, 5 ] +const test3 = [ 102345, 99, 34, 87, 135, 8, 3, 7, 99, 101, 3657, 2, 1, 5, 4, 3 ]; +console.log(`TEST #3 UNSORTED: ${test3}`); +console.log(`TEST #3 SORTED: ${bubbleSort(test3)}`); +// ---> [ 1, 2, 3, 3, 4, 5, 7, 8, 34, 87, 99, 99, 101, 135, 3657, 102345 ] From 7bb9277eccd03947ae231a01940d05c13cc5beac Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 29 Jul 2017 20:36:31 -0400 Subject: [PATCH 179/523] =?UTF-8?q?cc15=20-=20bubbleSort=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bubbleSort/bubbleSort.js | 68 +++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index 6024d22..408a121 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -1,24 +1,29 @@ // Code Challenge # 15 -const bubbleSort = (arr, mod = 0) => { - - // compare (current/next) second pairs per each index +// INPUT: array of numbers +// FUNCTION: sort from {array[0]: low} to {array[n-1]: high} +// OUTPUT: sorted array +const bubbleSort = (arr, count = 0) => { + // compare all (current/next) index pairs for (let i = 0; i < arr.length; i++) { - // counter to track if sorting is done - let modify = mod; + // index pairs let current = arr[i]; let next = arr[i + 1]; + // counter to track sorting passes + let sorting = count; - // if current is greater than next, swap & increment modification counter - // else, reset modification counter to zero to prevent recursive call + // IF current is greater than next, + // THEN swap index pairs & increment sorting counter. + // ELSE reset sorting counter to zero (to prevent recursive call) if (current > next) { arr[i] = next; arr[i + 1] = current; - modify++; - } else modify = 0; + sorting++; + } else sorting = 0; - // if list not sorted, - if (modify !== 0) { + // IF index pairs were swapped, + // THEN recursively call function until sorting count is 0 + if (sorting !== 0) { // // UNCOMMENT TO CONSOLE.LOG() EACH PASS // if (modify > 9) { // console.log(`Sorting pass #${modify}: ${arr}`); @@ -26,24 +31,57 @@ const bubbleSort = (arr, mod = 0) => { // console.log(`Sorting pass #${modify}: ${arr}`); // } - // ...then recursively call function until modify count is 0 - bubbleSort(arr, modify) + bubbleSort(arr, sorting) } }; - // return sorted array return arr; }; +// TEST SUITE +// BASIC SORTING OF THE NATURAL NUMBERS const test1 = [ 2, 1, 3 ]; console.log(`TEST #1 UNSORTED: ${test1}`); console.log(`TEST #1 SORTED: ${bubbleSort(test1)}\n`); // ---> [ 1, 2, 3 ] + const test2 = [ 3, 2, 1, 3, 1, 5, 4, 3 ]; console.log(`TEST #2 UNSORTED: ${test2}`); console.log(`TEST #2 SORTED: ${bubbleSort(test2)}\n`); // ---> [ 1, 1, 2, 3, 3, 3, 4, 5 ] + const test3 = [ 102345, 99, 34, 87, 135, 8, 3, 7, 99, 101, 3657, 2, 1, 5, 4, 3 ]; console.log(`TEST #3 UNSORTED: ${test3}`); -console.log(`TEST #3 SORTED: ${bubbleSort(test3)}`); +console.log(`TEST #3 SORTED: ${bubbleSort(test3)}\n`); // ---> [ 1, 2, 3, 3, 4, 5, 7, 8, 34, 87, 99, 99, 101, 135, 3657, 102345 ] + +// EDGE CASE HANDLING? +// NEGATIVE INTEGERS +const test4 = [ 3, 2, 1, -1, 0 ] +console.log(`TEST #4 UNSORTED: ${test4}`); +console.log(`TEST #4 SORTED: ${bubbleSort(test4)}\n`); +// ---> [ -1, 0, 1, 2, 3 ] + +// DECIMALS +const test5 = [ 3.2, -2.5, 1, -1, 0.32 ] +console.log(`TEST #5 UNSORTED: ${test5}`); +console.log(`TEST #5 SORTED: ${bubbleSort(test5)}\n`); +// ---> [ -2.5, -1, 0.32, 1, 3.2 ] + +// IRRATIONALS & EXPRESSIONS +const test6 = [ Math.PI, -2.5, 1, ( Math.E - 1 ), 0.32 ] +console.log(`TEST #6 UNSORTED: ${test6}`); +console.log(`TEST #6 SORTED: ${bubbleSort(test6)}\n`); +// ---> [ -2.5, 0.32, 1, 1.718281828459045, 3.141592653589793 ] + + + +/* +ANALYSIS: +1. This algorithm modifies the original array. How to not alter the original? + - let sorting = arr.slice(0); + - Tried this and replacing subsequent arr variables, but it made an unending loop? +2. Order of complexit: Quadratic with a recursive call to a for loop? +3. Edge cases? Negative numbers, decimals, irrationals, expressions? + +*/ From 637ea306ab156a83be8eeb522bf26d4ee4865a0e Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sat, 29 Jul 2017 20:45:44 -0400 Subject: [PATCH 180/523] =?UTF-8?q?cc15=20bubbleSort=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bubbleSort/bubbleSort.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index 408a121..026783a 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -77,11 +77,27 @@ console.log(`TEST #6 SORTED: ${bubbleSort(test6)}\n`); /* + ANALYSIS: -1. This algorithm modifies the original array. How to not alter the original? +1. Order of complexity: Quadratic with a recursive call to a for loop? +2. Other edge cases? +3. This algorithm modifies the original array. How to not alter the original? - let sorting = arr.slice(0); - Tried this and replacing subsequent arr variables, but it made an unending loop? -2. Order of complexit: Quadratic with a recursive call to a for loop? -3. Edge cases? Negative numbers, decimals, irrationals, expressions? + - slice makes a non destructive copy... WHY? OH, WHY?????? + ```console + $ node + > x = [1, 2, 3, 4] + [ 1, 2, 3, 4 ] + > y = x.slice(0) + [ 1, 2, 3, 4 ] + > y[1] = 99 + 99 + > x + [ 1, 2, 3, 4 ] + > y + [ 1, 99, 3, 4 ] + ``` + - splice made it so nothing returns... :\ */ From 842742ff5a7d55efa5b27fea6e44a2eefde97bc6 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Sun, 30 Jul 2017 03:32:20 -0400 Subject: [PATCH 181/523] =?UTF-8?q?cc15=20bubbleSort=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bubbleSort/bubbleSort.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index 026783a..1bbc83f 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -81,6 +81,7 @@ console.log(`TEST #6 SORTED: ${bubbleSort(test6)}\n`); ANALYSIS: 1. Order of complexity: Quadratic with a recursive call to a for loop? 2. Other edge cases? + - `if (current > next)` should I and how would I check for the undefined value of array[n + 1]? 3. This algorithm modifies the original array. How to not alter the original? - let sorting = arr.slice(0); - Tried this and replacing subsequent arr variables, but it made an unending loop? From 4a1612ea90e451322cc0f7e67713ee6a3f53be9f Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 31 Jul 2017 11:59:37 -0400 Subject: [PATCH 182/523] cc17 allAnagrams --- allAnagrams/allAnagrams.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/allAnagrams/allAnagrams.js b/allAnagrams/allAnagrams.js index a214c6a..2935bae 100644 --- a/allAnagrams/allAnagrams.js +++ b/allAnagrams/allAnagrams.js @@ -1,3 +1,5 @@ +// Code Challenge # 17 + /** * Given a single input string, write a function that produces all possible anagrams * of a string and outputs them as an array. At first, don't worry about @@ -10,4 +12,4 @@ * example usage: * const anagrams = allAnagrams('abc'); * console.log(anagrams); // [ 'abc', 'acb', 'bac', 'bca', 'cab', 'cba' ] - */ \ No newline at end of file + */ From 03f2566d09f11add40cf24e6371102307b9989ba Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 31 Jul 2017 12:00:28 -0400 Subject: [PATCH 183/523] cc17 - allAnagrams --- allAnagrams/allAnagrams.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/allAnagrams/allAnagrams.js b/allAnagrams/allAnagrams.js index 2935bae..5b247a6 100644 --- a/allAnagrams/allAnagrams.js +++ b/allAnagrams/allAnagrams.js @@ -1,4 +1,4 @@ -// Code Challenge # 17 +// Code Challenge # 16 /** * Given a single input string, write a function that produces all possible anagrams From 15b98bc212a627803bc74284d2fba3e2ad3f60aa Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 31 Jul 2017 12:32:38 -0400 Subject: [PATCH 184/523] thinking --- allAnagrams/allAnagrams.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/allAnagrams/allAnagrams.js b/allAnagrams/allAnagrams.js index 5b247a6..0eccba0 100644 --- a/allAnagrams/allAnagrams.js +++ b/allAnagrams/allAnagrams.js @@ -1,15 +1,23 @@ // Code Challenge # 16 - /** * Given a single input string, write a function that produces all possible anagrams * of a string and outputs them as an array. At first, don't worry about * repeated strings. What time complexity is your solution? * * Extra credit: Deduplicate your return array. - */ -/** * example usage: * const anagrams = allAnagrams('abc'); * console.log(anagrams); // [ 'abc', 'acb', 'bac', 'bca', 'cab', 'cba' ] - */ + +// INPUT: a string +// FUNCTION: return all possible combinations of letterss +// OUTPUT: array of string permutations + +// SOLUTION: slice off the first letter, swap the next two letters, recombine the swapped letters with the first letter... Hmmm... + +*/ + +cont allAnagrams = (str) => { + +} From fca2b2a59ee76e26f441055a56bfb86eb2337db3 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 31 Jul 2017 13:02:38 -0400 Subject: [PATCH 185/523] minimum case handling --- allAnagrams/allAnagrams.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/allAnagrams/allAnagrams.js b/allAnagrams/allAnagrams.js index 0eccba0..bf8efda 100644 --- a/allAnagrams/allAnagrams.js +++ b/allAnagrams/allAnagrams.js @@ -15,9 +15,36 @@ // OUTPUT: array of string permutations // SOLUTION: slice off the first letter, swap the next two letters, recombine the swapped letters with the first letter... Hmmm... + slice vs splice? slice doesn't change original, splice does. */ -cont allAnagrams = (str) => { - +const allAnagrams = (str) => { + x = [] + if (str.length === 0) { + x.push(str); + return x; + }; + if (str.length === 1) { + x.push(str); + return `one character is already all anagram permutations: ${x}`; + }; + if (str.length === 2 && str[0] != str [1]) { + str[0] = str[1]; + str[1] = str[0]; + x.push(str); + return `swapped: ${x}`; + } else { + x.push(str); + return `there's nothing to do with: ${x}`; + }; } + +// TEST SUITE +// Empty string or one character +const emptyString = '' +console.log(allAnagrams(emptyString)); +console.log(allAnagrams('a')); +// Two character string +console.log(allAnagrams('aa')); +console.log(allAnagrams('ab')); From fa4ff46a59982dcf6813aff1d5b817809b5cd25e Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 31 Jul 2017 13:08:17 -0400 Subject: [PATCH 186/523] cc15 - bubbleSort Review lecture --- bubbleSort/bubbleSort.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index 1bbc83f..6c41d7f 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -55,24 +55,24 @@ console.log(`TEST #3 UNSORTED: ${test3}`); console.log(`TEST #3 SORTED: ${bubbleSort(test3)}\n`); // ---> [ 1, 2, 3, 3, 4, 5, 7, 8, 34, 87, 99, 99, 101, 135, 3657, 102345 ] -// EDGE CASE HANDLING? -// NEGATIVE INTEGERS -const test4 = [ 3, 2, 1, -1, 0 ] -console.log(`TEST #4 UNSORTED: ${test4}`); -console.log(`TEST #4 SORTED: ${bubbleSort(test4)}\n`); -// ---> [ -1, 0, 1, 2, 3 ] - -// DECIMALS -const test5 = [ 3.2, -2.5, 1, -1, 0.32 ] -console.log(`TEST #5 UNSORTED: ${test5}`); -console.log(`TEST #5 SORTED: ${bubbleSort(test5)}\n`); -// ---> [ -2.5, -1, 0.32, 1, 3.2 ] - -// IRRATIONALS & EXPRESSIONS -const test6 = [ Math.PI, -2.5, 1, ( Math.E - 1 ), 0.32 ] -console.log(`TEST #6 UNSORTED: ${test6}`); -console.log(`TEST #6 SORTED: ${bubbleSort(test6)}\n`); -// ---> [ -2.5, 0.32, 1, 1.718281828459045, 3.141592653589793 ] +// // EDGE CASE HANDLING? +// // NEGATIVE INTEGERS +// const test4 = [ 3, 2, 1, -1, 0 ] +// console.log(`TEST #4 UNSORTED: ${test4}`); +// console.log(`TEST #4 SORTED: ${bubbleSort(test4)}\n`); +// // ---> [ -1, 0, 1, 2, 3 ] +// +// // DECIMALS +// const test5 = [ 3.2, -2.5, 1, -1, 0.32 ] +// console.log(`TEST #5 UNSORTED: ${test5}`); +// console.log(`TEST #5 SORTED: ${bubbleSort(test5)}\n`); +// // ---> [ -2.5, -1, 0.32, 1, 3.2 ] +// +// // IRRATIONALS & EXPRESSIONS +// const test6 = [ Math.PI, -2.5, 1, ( Math.E - 1 ), 0.32 ] +// console.log(`TEST #6 UNSORTED: ${test6}`); +// console.log(`TEST #6 SORTED: ${bubbleSort(test6)}\n`); +// // ---> [ -2.5, 0.32, 1, 1.718281828459045, 3.141592653589793 ] From 85f9a334db404f773ecafaab63fee0565cf98b6d Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 31 Jul 2017 13:24:22 -0400 Subject: [PATCH 187/523] cc15 review lecture --- bubbleSort/Tai_solution.js | 18 ++++++++++++++++++ bubbleSort/bubbleSort.js | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 bubbleSort/Tai_solution.js diff --git a/bubbleSort/Tai_solution.js b/bubbleSort/Tai_solution.js new file mode 100644 index 0000000..d61c58f --- /dev/null +++ b/bubbleSort/Tai_solution.js @@ -0,0 +1,18 @@ +const bubbleSort = (arr) => { + let swappedValue; + do { + swappedValue = false; + for (let i = 0; i < arr.length; i++) { + console.log(arr); + if (arr[i] > arr[i + 1]) { // [2, 1, 3] + let temp = arr[i]; // temp = 2 + arr[i] = arr[i + 1]; // [1, 1, 3] temp = 2; + arr[i + 1] = temp; // [1, 2, 3]; + swappedValue = true; + } + } + } while (swappedValue); + return arr; +}; + +console.log(bubbleSort([5, 6, 7, 3, 2, 1])); // returns [1, 2, 3] diff --git a/bubbleSort/bubbleSort.js b/bubbleSort/bubbleSort.js index 6c41d7f..a29cad5 100644 --- a/bubbleSort/bubbleSort.js +++ b/bubbleSort/bubbleSort.js @@ -79,7 +79,8 @@ console.log(`TEST #3 SORTED: ${bubbleSort(test3)}\n`); /* ANALYSIS: -1. Order of complexity: Quadratic with a recursive call to a for loop? +1. Order of complexity: Quadratic due to the recursive call to a for loop? + - O(n^2) 2. Other edge cases? - `if (current > next)` should I and how would I check for the undefined value of array[n + 1]? 3. This algorithm modifies the original array. How to not alter the original? From d55925b15468d303839e9bb8aac6ed5d3e2d45ad Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 31 Jul 2017 13:26:19 -0400 Subject: [PATCH 188/523] cc16 - allAnagrams wip --- allAnagrams/allAnagrams.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/allAnagrams/allAnagrams.js b/allAnagrams/allAnagrams.js index bf8efda..7d9121c 100644 --- a/allAnagrams/allAnagrams.js +++ b/allAnagrams/allAnagrams.js @@ -41,9 +41,10 @@ const allAnagrams = (str) => { } // TEST SUITE -// Empty string or one character +// Empty string const emptyString = '' console.log(allAnagrams(emptyString)); +// One character console.log(allAnagrams('a')); // Two character string console.log(allAnagrams('aa')); From c0c01562609bcee3272567a59fd7494b986243ee Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 31 Jul 2017 22:44:13 -0400 Subject: [PATCH 189/523] a factorial solution? --- allAnagrams/allAnagrams.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/allAnagrams/allAnagrams.js b/allAnagrams/allAnagrams.js index 7d9121c..820fc17 100644 --- a/allAnagrams/allAnagrams.js +++ b/allAnagrams/allAnagrams.js @@ -17,6 +17,8 @@ // SOLUTION: slice off the first letter, swap the next two letters, recombine the swapped letters with the first letter... Hmmm... slice vs splice? slice doesn't change original, splice does. +// After looking at brute solutions, it seems there is a factorial operation going on here such that a string of 5 characters would have 5! solutions... +// hmmm! */ const allAnagrams = (str) => { From a70ff2d938c35ccb88de2ac96fb8ea0fbc25fc4d Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 1 Aug 2017 11:58:47 -0400 Subject: [PATCH 190/523] refactoring --- allAnagrams/allAnagrams.js | 63 +++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/allAnagrams/allAnagrams.js b/allAnagrams/allAnagrams.js index 820fc17..880f200 100644 --- a/allAnagrams/allAnagrams.js +++ b/allAnagrams/allAnagrams.js @@ -22,26 +22,34 @@ */ const allAnagrams = (str) => { - x = [] - if (str.length === 0) { - x.push(str); - return x; - }; - if (str.length === 1) { - x.push(str); - return `one character is already all anagram permutations: ${x}`; - }; - if (str.length === 2 && str[0] != str [1]) { - str[0] = str[1]; - str[1] = str[0]; - x.push(str); - return `swapped: ${x}`; - } else { - x.push(str); - return `there's nothing to do with: ${x}`; - }; + arr = str.split(''); + + + + return str, arr; } +// const allAnagrams = (str) => { +// x = [] +// if (str.length === 0) { +// x.push(str); +// return x; +// }; +// if (str.length === 1) { +// x.push(str); +// return `one character is already all anagram permutations: ${x}`; +// }; +// if (str.length === 2 && str[0] != str [1]) { +// str[0] = str[1]; +// str[1] = str[0]; +// x.push(str); +// return `I took your ${str} and swapped it: ${x}`; // <--- oh, ha... yeah... +// } else { +// x.push(str); +// return `there's nothing to do with: ${x}`; +// }; +// } + // TEST SUITE // Empty string const emptyString = '' @@ -51,3 +59,22 @@ console.log(allAnagrams('a')); // Two character string console.log(allAnagrams('aa')); console.log(allAnagrams('ab')); + + +// FACTORIAL +const nFactorial = (n) => { + // factorial example: !5 = 5 * 4 * 3 * 2 * 1 + // return the factorial of `n` + + // // version 1 √ + if (n === 1) return n; + return n * nFactorial(n - 1); + + // // version 2: ternary solution √ + // // declare variableName = ifCondition ? thenThis : otherwiseThat; + // const factorial = (n === 1) ? 1 : n * nFactorial(n - 1); + // return factorial; + + // // version 2.1 √ + // return (n === 1) ? n : n * nFactorial(n - 1); +}; From 26a0e280debde542a3f0060a3b381efadbd67ce2 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 2 Aug 2017 10:35:07 -0400 Subject: [PATCH 191/523] Sean's solution from review lecture --- allAnagrams/Seans_solution.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 allAnagrams/Seans_solution.js diff --git a/allAnagrams/Seans_solution.js b/allAnagrams/Seans_solution.js new file mode 100644 index 0000000..ab34642 --- /dev/null +++ b/allAnagrams/Seans_solution.js @@ -0,0 +1,12 @@ +const allAnagrams = (str, start = '') => { + if (str.length === 1) return [start + str]; + const anagrams = []; + + for (let i = 0; i < str.length; i++) { + const result = allAnagrams(str.substr(0, i) + str.substr(i + 1), str[i]); + for (let j = 0; j < result.length; j++) { + anagrams.push(start + result[j]); + } + } + return anagrams; +}; From d025e88ebff0df6e6aad7426bfd2bad8f051d231 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 2 Aug 2017 10:35:17 -0400 Subject: [PATCH 192/523] Wesley's solution posted to Slack --- allAnagrams/Wesleys_solution.js | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 allAnagrams/Wesleys_solution.js diff --git a/allAnagrams/Wesleys_solution.js b/allAnagrams/Wesleys_solution.js new file mode 100644 index 0000000..49f0715 --- /dev/null +++ b/allAnagrams/Wesleys_solution.js @@ -0,0 +1,39 @@ +class Anagram { + constructor(string, letter = null) { + this.string = string; + this.letter = letter; + this.children = []; + this.answer = []; + this.divide(); + this.produce(); + } + + divide() { + const arr = this.string.split(''); + arr.forEach(l => { + const rest = arr.filter(x => x !== l).join(''); + const anagram = new Anagram(rest, l); + this.children.push(anagram); + }); + } + + produce(a = this, b = null) { + if (a.letter) { + b = b ? b.concat(a.letter) : a.letter; + } + if (a.children.length) { + a.children.forEach(aa => { + return this.produce(aa, b ? b : null) + }); + return this.answer; + } + this.answer.push(b); + } +} + +function allAnagrams(s) { + return (new Anagram(s)).answer; +} + +const anagrams = allAnagrams('abcdefghi'); +console.log(anagrams); From e296c357c90972ac8d4b4578a349e4ab143eea32 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 2 Aug 2017 10:35:48 -0400 Subject: [PATCH 193/523] =?UTF-8?q?cc16=20allAnagrams=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- allAnagrams/allAnagrams.js | 76 ++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/allAnagrams/allAnagrams.js b/allAnagrams/allAnagrams.js index 880f200..f6f45d4 100644 --- a/allAnagrams/allAnagrams.js +++ b/allAnagrams/allAnagrams.js @@ -19,46 +19,58 @@ // After looking at brute solutions, it seems there is a factorial operation going on here such that a string of 5 characters would have 5! solutions... // hmmm! +// get the first letter and use the length of the string to slice the remainder of the string, as the for loop continues */ + + + const allAnagrams = (str) => { - arr = str.split(''); + if (str.length < 2) return str; + + const result = []; + for (let i = 0; i < str.length; i++) { + let firstLetter = str[i]; + let restOfString = str.slice(0, i) + str.slice(i + 1, str.length); - return str, arr; + for (let sub of allAnagrams(restOfString)) { + result.push(firstLetter + sub); + } + } + return result; } -// const allAnagrams = (str) => { -// x = [] -// if (str.length === 0) { -// x.push(str); -// return x; -// }; -// if (str.length === 1) { -// x.push(str); -// return `one character is already all anagram permutations: ${x}`; -// }; -// if (str.length === 2 && str[0] != str [1]) { -// str[0] = str[1]; -// str[1] = str[0]; -// x.push(str); -// return `I took your ${str} and swapped it: ${x}`; // <--- oh, ha... yeah... -// } else { -// x.push(str); -// return `there's nothing to do with: ${x}`; -// }; -// } - -// TEST SUITE -// Empty string -const emptyString = '' -console.log(allAnagrams(emptyString)); -// One character -console.log(allAnagrams('a')); -// Two character string -console.log(allAnagrams('aa')); -console.log(allAnagrams('ab')); +console.log(allAnagrams('abc')); + + + + + + + + +// const result = [], temp = []; +// +// allAnagrams = (str) => { +// const chars = str.split(''); +// +// for (let i = 0; i < chars.length; i++) { +// const subStr = chars.splice(i, 1); +// temp.push(subStr); +// if (chars.length == 0) +// result[result.length] = temp.join(''); +// allAnagrams(chars.join('')); +// chars.splice(i, 0, subStr); +// temp.pop(); +// } +// return result +// }; +// +// +// console.log(allAnagrams('abc')); + // FACTORIAL From b188984cc5a81d28bbf99e175a79eee144288cd0 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 2 Aug 2017 10:36:08 -0400 Subject: [PATCH 194/523] cc17 insertionSort wip --- insertionSort/insertionSort.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/insertionSort/insertionSort.js b/insertionSort/insertionSort.js index d8b0db9..d5c05c6 100644 --- a/insertionSort/insertionSort.js +++ b/insertionSort/insertionSort.js @@ -1,4 +1,5 @@ /** + CODE CHALLENGE #17 * Insertion sort is a basic sorting algorithm. Insertion sort * iterates over an array, growing a sorted array behind the current location. * It takes each element from the input and finds the spot, up to the current point, @@ -13,4 +14,4 @@ const insertionSort = (array) => { // Your code goes here. Feel free to add helper functions if needed. return array; -}; \ No newline at end of file +}; From 2c5f94c6e84e12d6d19864f7a3fc74774fd26a28 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 2 Aug 2017 10:41:27 -0400 Subject: [PATCH 195/523] =?UTF-8?q?cc16=20allAnagrams=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- allAnagrams/allAnagrams.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/allAnagrams/allAnagrams.js b/allAnagrams/allAnagrams.js index f6f45d4..4315279 100644 --- a/allAnagrams/allAnagrams.js +++ b/allAnagrams/allAnagrams.js @@ -20,6 +20,8 @@ // After looking at brute solutions, it seems there is a factorial operation going on here such that a string of 5 characters would have 5! solutions... // hmmm! // get the first letter and use the length of the string to slice the remainder of the string, as the for loop continues + +// To deduplicate, just new Set(array of anagrams) */ From 360aff276b8f9d96da141d89866ab1ac569525d9 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 2 Aug 2017 12:03:40 -0400 Subject: [PATCH 196/523] =?UTF-8?q?cc18=20insertionsSort=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- insertionSort/insertionSort.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/insertionSort/insertionSort.js b/insertionSort/insertionSort.js index d5c05c6..7cdc7c6 100644 --- a/insertionSort/insertionSort.js +++ b/insertionSort/insertionSort.js @@ -12,6 +12,20 @@ // insertionSort([2, 1, 3, 7, 4, 2, 9, 3, 8]); // yields [1, 2, 2, 3, 3, 4, 7, 8, 9] const insertionSort = (array) => { - // Your code goes here. Feel free to add helper functions if needed. + for(let i = 0; i < array.length; i++) { + let temp = array[i]; + let j = i - 1; + while (j >= 0 && array[j] > temp) { + console.log(temp, array); + array[j + 1] = array[j]; + j--; + } + array[j + 1] = temp; + } return array; }; + + +// TEST SUITE +// console.log(insertionSort([2, 1, 3, 7, 4, 2, 9, 3, 8])); // yields [1, 2, 2, 3, 3, 4, 7, 8, 9] +console.log(insertionSort([9, 8, 7, 6, 5, 4, 3, 2, 1])); // yields [1, 2, 3, 4, 5, 6, 7, 8, 9] From ef7b8d10d66d7332e1ac5c08c5c0fd0ce3dae0b0 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 2 Aug 2017 12:21:06 -0400 Subject: [PATCH 197/523] cc18 rotateImage wip --- rotateImage/rotateImage.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/rotateImage/rotateImage.js b/rotateImage/rotateImage.js index a75ea9e..1878ce7 100644 --- a/rotateImage/rotateImage.js +++ b/rotateImage/rotateImage.js @@ -1,2 +1,36 @@ +// cc18 rotateImage + // Given an image represented by an NxN matrix, where each pixel in the image is an integer from 0 - 9, // write a method to rotate the image by 90 degrees. Can you do this in place? + +/* +INPUT: (9x9 image matrix) +const exampleImageArray = [ + [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], + [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], + [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], + [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], + [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], + [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], + [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], + [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], + [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], +] + +FUNCTION: 90 degree clockwise rotation + +OUTPUT: +[ + [ 0. 0. 0. 0. 0. 0. 0. 0. 0 ], + [ 1, 1, 1, 1, 1, 1, 1, 1, 1 ], + [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ], + [ 3, 3, 3, 3, 3, 3, 3, 3, 3 ], + [ 4, 4, 4, 4, 4, 4, 4, 4, 4 ], + [ 5, 5, 5, 5, 5, 5, 5, 5, 5 ], + [ 6, 6, 6, 6, 6, 6, 6, 6, 6 ], + [ 7, 7, 7, 7, 7, 7, 7, 7, 7 ], + [ 8, 8, 8, 8, 8, 8, 8, 8, 8 ], + [ 9, 9, 9, 9, 9, 9, 9, 9, 9 ], +] + +*/ From e18f9d6129f18016f7aa9bece6ae2ab1db2420f9 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 2 Aug 2017 13:06:07 -0400 Subject: [PATCH 198/523] cc18 rotateImage setup --- rotateImage/rotateImage.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/rotateImage/rotateImage.js b/rotateImage/rotateImage.js index 1878ce7..b65c20d 100644 --- a/rotateImage/rotateImage.js +++ b/rotateImage/rotateImage.js @@ -6,22 +6,22 @@ /* INPUT: (9x9 image matrix) const exampleImageArray = [ - [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], - [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], - [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], - [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], - [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], - [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], - [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], - [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], - [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], ] FUNCTION: 90 degree clockwise rotation OUTPUT: [ - [ 0. 0. 0. 0. 0. 0. 0. 0. 0 ], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ], [ 1, 1, 1, 1, 1, 1, 1, 1, 1 ], [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ], [ 3, 3, 3, 3, 3, 3, 3, 3, 3 ], From d7833e4a4740fad1165df6794bfb142c2539f106 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 2 Aug 2017 13:31:14 -0400 Subject: [PATCH 199/523] =?UTF-8?q?cc17=20insertionSort=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- insertionSort/insertionSort.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/insertionSort/insertionSort.js b/insertionSort/insertionSort.js index 7cdc7c6..4037174 100644 --- a/insertionSort/insertionSort.js +++ b/insertionSort/insertionSort.js @@ -13,10 +13,11 @@ const insertionSort = (array) => { for(let i = 0; i < array.length; i++) { + // console.log('step', i, array); let temp = array[i]; let j = i - 1; while (j >= 0 && array[j] > temp) { - console.log(temp, array); + // console.log('step', i, j, array); array[j + 1] = array[j]; j--; } @@ -28,4 +29,4 @@ const insertionSort = (array) => { // TEST SUITE // console.log(insertionSort([2, 1, 3, 7, 4, 2, 9, 3, 8])); // yields [1, 2, 2, 3, 3, 4, 7, 8, 9] -console.log(insertionSort([9, 8, 7, 6, 5, 4, 3, 2, 1])); // yields [1, 2, 3, 4, 5, 6, 7, 8, 9] +console.log("Tada:", insertionSort([9, 8, 7, 6, 5, 4, 3, 2, 1, ])); // yields [1, 2, 2, 3, 3, 4, 7, 8, 9] From b1fbbebf6fd5d1ed1e9268fc3ca7fafaf3d5e458 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 2 Aug 2017 13:31:31 -0400 Subject: [PATCH 200/523] cc17 Tai's lecture solution --- insertionSort/Tais_solution.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 insertionSort/Tais_solution.js diff --git a/insertionSort/Tais_solution.js b/insertionSort/Tais_solution.js new file mode 100644 index 0000000..c1e78e7 --- /dev/null +++ b/insertionSort/Tais_solution.js @@ -0,0 +1,28 @@ +/** + * Insertion sort is a basic sorting algorithm. Insertion sort + * iterates over an array, growing a sorted array behind the current location. + * It takes each element from the input and finds the spot, up to the current point, + * where that element belongs. It does this until it gets to the end of the array. + * https://en.wikipedia.org/wiki/Insertion_sort + * https://www.khanacademy.org/computing/computer-science/algorithms#insertion-sort + **/ + +// Example usage: +// insertionSort([2, 1, 3, 7, 4, 2, 9, 3, 8]); // yields [1, 2, 2, 3, 3, 4, 7, 8, 9] + +const insertionSort = (array) => { + // Your code goes here. Feel free to add helper functions if needed. + for (let i = 1; i < array.length; i++) { + let temp = array[i]; + let j; + for (j = i - 1; j >=0 && array[j] > temp; j--) { + array[j + 1] = array[j]; + } + array[j + 1] = temp; + } + return array; +}; + +const val = insertionSort([2, 1, 3, 7, 4, 2, 9, 3, 8]); +// yields [1, 2, 2, 3, 3, 4, 7, 8, 9] +console.log(val); From 2f9825a2c4e90c295da5074e2f71e4d7dec5dc27 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 2 Aug 2017 13:32:15 -0400 Subject: [PATCH 201/523] =?UTF-8?q?cc17=20insertionSort=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- insertionSort/insertionSort.js | 1 + 1 file changed, 1 insertion(+) diff --git a/insertionSort/insertionSort.js b/insertionSort/insertionSort.js index 4037174..14df492 100644 --- a/insertionSort/insertionSort.js +++ b/insertionSort/insertionSort.js @@ -5,6 +5,7 @@ * It takes each element from the input and finds the spot, up to the current point, * where that element belongs. It does this until it gets to the end of the array. * https://en.wikipedia.org/wiki/Insertion_sort + - complexity O(n^2) * https://www.khanacademy.org/computing/computer-science/algorithms#insertion-sort **/ From ad48741bf70df5b497a85809dee3bbbabdb595ea Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 03:26:12 -0400 Subject: [PATCH 202/523] off by 1... --- rotateImage/rotateImage.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/rotateImage/rotateImage.js b/rotateImage/rotateImage.js index b65c20d..d4964cb 100644 --- a/rotateImage/rotateImage.js +++ b/rotateImage/rotateImage.js @@ -3,6 +3,34 @@ // Given an image represented by an NxN matrix, where each pixel in the image is an integer from 0 - 9, // write a method to rotate the image by 90 degrees. Can you do this in place? +// for each row (array), take the column (index) and put each +// corresponding index value in an array, so row 1-9 col (index) 0 become an array, +// then row1-9 col (index) 1 and so on. + +const rotateImage = (arr) => { + const len = arr.length; + rotation = Array(len).fill().map(()=> []); + for (let col = 0; col < len; col++) { + for (let row = 0; row < len; row ++) { + rotation[col].push(arr[row][col]); + } + } + return rotation; +} + +console.log(rotateImage([ + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], +] +)); + /* INPUT: (9x9 image matrix) const exampleImageArray = [ From a5018dc9d55836ce8b6a1aac4ede6c57979e6bcd Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 03:33:13 -0400 Subject: [PATCH 203/523] =?UTF-8?q?cc18=20rotateImage=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rotateImage/rotateImage.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rotateImage/rotateImage.js b/rotateImage/rotateImage.js index d4964cb..71840d1 100644 --- a/rotateImage/rotateImage.js +++ b/rotateImage/rotateImage.js @@ -7,6 +7,9 @@ // corresponding index value in an array, so row 1-9 col (index) 0 become an array, // then row1-9 col (index) 1 and so on. + +// this seems to only work for square matrixes +// no idea how I'd do it in place const rotateImage = (arr) => { const len = arr.length; rotation = Array(len).fill().map(()=> []); @@ -18,6 +21,7 @@ const rotateImage = (arr) => { return rotation; } +// 10x10 array console.log(rotateImage([ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], @@ -28,6 +32,16 @@ console.log(rotateImage([ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] +] +)); + +// 4x4 array +console.log(rotateImage([ + [ 0, 1, 2, 3 ], + [ 0, 1, 2, 3 ], + [ 0, 1, 2, 3 ], + [ 0, 1, 2, 3 ] ] )); From 9ae149b72fa6b408f9b4c52aa224ab864591fd34 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 03:35:04 -0400 Subject: [PATCH 204/523] not quite in place --- rotateImage/rotateImage.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/rotateImage/rotateImage.js b/rotateImage/rotateImage.js index 71840d1..69a4c05 100644 --- a/rotateImage/rotateImage.js +++ b/rotateImage/rotateImage.js @@ -45,6 +45,27 @@ console.log(rotateImage([ ] )); +// Not quite +const rotateImageInPlace = (arr) => { + const len = arr.length; + // rotation = Array(len).fill().map(()=> []); + for (let col = 0; col < len; col++) { + for (let row = 0; row < len; row ++) { + arr[col].push(arr[row][col]); + } + } + return arr; +} + +// 4x4 array +console.log(rotateImageInPlace([ + [ 0, 1, 2, 3 ], + [ 0, 1, 2, 3 ], + [ 0, 1, 2, 3 ], + [ 0, 1, 2, 3 ] +] +)); + /* INPUT: (9x9 image matrix) const exampleImageArray = [ From 5f4231ac4a50ae2067f8fbaba07704545c1e80e5 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 12:10:46 -0400 Subject: [PATCH 205/523] truth table --- logicGates/logicGates.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/logicGates/logicGates.js b/logicGates/logicGates.js index 6433782..5cac627 100644 --- a/logicGates/logicGates.js +++ b/logicGates/logicGates.js @@ -9,24 +9,48 @@ * All functions should return a 1 for true and a 0 for false. */ +// (Not And) operator +// T !&& T +// T !&& F +// F !&& T +// F !&& F const NAND = (x, y) => { // You can use whatever JS operators that you would like: &&, ||, ! }; + +// Not operator +// !T --> F +// !F --> T const NOT = (n) => { // Do not use !, &&, or || }; +// AND +// T && T ---> T +// T && F ---> F +// F && T ---> F +// F && F ---> F const AND = (x, y) => { // Do not use &&, ||, or ! // You can use any of the functions that you have already written }; +// INclusive OR +// T || T ---> T +// T || F ---> T +// F || T ---> T +// F || F ---> F const OR = (x, y) => { // Do not use ||, &&, or ! // You can use any of the functions that you have already written }; +// EXclusive OR +// T X T ---> F +// T X F ---> T +// F X T ---> T +// F X F ---> F const XOR = (x, y) => { // Do not use ||, &&, or ! // You can use any of the functions that you have already written From 5fad5a66c353f23bd870c0dafe62ae2944df1836 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 12:11:25 -0400 Subject: [PATCH 206/523] idem --- logicGates/logicGates.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/logicGates/logicGates.js b/logicGates/logicGates.js index 5cac627..87ba841 100644 --- a/logicGates/logicGates.js +++ b/logicGates/logicGates.js @@ -10,10 +10,10 @@ */ // (Not And) operator -// T !&& T -// T !&& F -// F !&& T -// F !&& F +// T !&& T ---> T +// T !&& F ---> F +// F !&& T ---> F +// F !&& F ---> F const NAND = (x, y) => { // You can use whatever JS operators that you would like: &&, ||, ! }; From aed1090d363b3e7b7a57c5413d2457628757ed7c Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 12:11:53 -0400 Subject: [PATCH 207/523] cc19 logicGates wip --- logicGates/logicGates.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/logicGates/logicGates.js b/logicGates/logicGates.js index 87ba841..a46bc22 100644 --- a/logicGates/logicGates.js +++ b/logicGates/logicGates.js @@ -1,3 +1,5 @@ +// cc19 logicGates + /* * For this coding challenge you will be recreating low level logic gates. * You will first create the NAND function and then you will create From d31238c2bbedf1f9391db18659d702abab001e7a Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 12:25:10 -0400 Subject: [PATCH 208/523] idem --- logicGates/logicGates.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/logicGates/logicGates.js b/logicGates/logicGates.js index a46bc22..fe852c9 100644 --- a/logicGates/logicGates.js +++ b/logicGates/logicGates.js @@ -11,15 +11,26 @@ * All functions should return a 1 for true and a 0 for false. */ -// (Not And) operator -// T !&& T ---> T -// T !&& F ---> F -// F !&& T ---> F -// F !&& F ---> F +// phi AND psi +// (T && T) ---> T +// (T && F) ---> F +// (F && T) ---> F +// (F && F) ---> F +// +// NOT (phi AND psi) operator +// !(T && T) ---> F +// !(T && F) ---> T +// !(F && T) ---> T +// !(F && F) ---> T const NAND = (x, y) => { // You can use whatever JS operators that you would like: &&, ||, ! + if (!(x && y)) { + return + } }; +console.log(NAND(1, 0)); + // Not operator // !T --> F From 78caa1272c3dfffae68ebcb20a027a0ef3483473 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 12:28:19 -0400 Subject: [PATCH 209/523] NAND --- logicGates/logicGates.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/logicGates/logicGates.js b/logicGates/logicGates.js index fe852c9..9e1cf1e 100644 --- a/logicGates/logicGates.js +++ b/logicGates/logicGates.js @@ -24,12 +24,16 @@ // !(F && F) ---> T const NAND = (x, y) => { // You can use whatever JS operators that you would like: &&, ||, ! - if (!(x && y)) { - return + if ( !(x && y) ) { + return 1; } + return 0; }; -console.log(NAND(1, 0)); +console.log(NAND(true, true)); // ---> 0 +console.log(NAND(true, false)); // ---> 1 +console.log(NAND(false, true)); // ---> 1 +console.log(NAND(false, false)); // ---> 1 // Not operator From 3a03c986e4de5e8dea268c0040f74220192b505c Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 12:30:42 -0400 Subject: [PATCH 210/523] NOT --- logicGates/logicGates.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/logicGates/logicGates.js b/logicGates/logicGates.js index 9e1cf1e..4295270 100644 --- a/logicGates/logicGates.js +++ b/logicGates/logicGates.js @@ -29,7 +29,7 @@ const NAND = (x, y) => { } return 0; }; - +console.log('NAND'); console.log(NAND(true, true)); // ---> 0 console.log(NAND(true, false)); // ---> 1 console.log(NAND(false, true)); // ---> 1 @@ -41,7 +41,11 @@ console.log(NAND(false, false)); // ---> 1 // !F --> T const NOT = (n) => { // Do not use !, &&, or || + return (NAND(n, n)); }; +console.log('NOT') +console.log(NOT(true)); // ---> 0 +console.log(NOT(false)); // ---> 1 // AND // T && T ---> T @@ -51,6 +55,7 @@ const NOT = (n) => { const AND = (x, y) => { // Do not use &&, ||, or ! // You can use any of the functions that you have already written + }; // INclusive OR From 1f87ce4aba11b0f055845112febaf05986832e6a Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 12:32:55 -0400 Subject: [PATCH 211/523] AND --- logicGates/logicGates.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/logicGates/logicGates.js b/logicGates/logicGates.js index 4295270..694a791 100644 --- a/logicGates/logicGates.js +++ b/logicGates/logicGates.js @@ -26,8 +26,7 @@ const NAND = (x, y) => { // You can use whatever JS operators that you would like: &&, ||, ! if ( !(x && y) ) { return 1; - } - return 0; + } return 0; }; console.log('NAND'); console.log(NAND(true, true)); // ---> 0 @@ -55,8 +54,16 @@ console.log(NOT(false)); // ---> 1 const AND = (x, y) => { // Do not use &&, ||, or ! // You can use any of the functions that you have already written - + if (NAND(x, y)) { + return 0; + } return 1; }; +console.log('AND'); +console.log(AND(true, true)); // ---> 1 +console.log(AND(true, false)); // ---> 0 +console.log(AND(false, true)); // ---> 0 +console.log(AND(false, false)); // ---> 0 + // INclusive OR // T || T ---> T From 00aafcb9fb3be7793b9a6d712aad98c18a65d8bc Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 12:41:11 -0400 Subject: [PATCH 212/523] OR / XOR --- logicGates/logicGates.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/logicGates/logicGates.js b/logicGates/logicGates.js index 694a791..eac4096 100644 --- a/logicGates/logicGates.js +++ b/logicGates/logicGates.js @@ -73,7 +73,16 @@ console.log(AND(false, false)); // ---> 0 const OR = (x, y) => { // Do not use ||, &&, or ! // You can use any of the functions that you have already written + if (x) return 1; + if (y) return 1; + return 0; }; +console.log('OR'); +console.log(OR(true, true)); // ---> 1 +console.log(OR(true, false)); // ---> 1 +console.log(OR(false, true)); // ---> 1 +console.log(OR(false, false)); // ---> 0 + // EXclusive OR // T X T ---> F @@ -83,4 +92,11 @@ const OR = (x, y) => { const XOR = (x, y) => { // Do not use ||, &&, or ! // You can use any of the functions that you have already written + if (x === y) return 0; + return 1; }; +console.log('XOR'); +console.log(XOR(true, true)); // ---> 0 +console.log(XOR(true, false)); // ---> 1 +console.log(XOR(false, true)); // ---> 1 +console.log(XOR(false, false)); // ---> 0 From 10b8e0a303c1e649a405458d87cff4901ba71e96 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 12:42:44 -0400 Subject: [PATCH 213/523] =?UTF-8?q?cc19=20logicGates=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logicGates/logicGates.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/logicGates/logicGates.js b/logicGates/logicGates.js index eac4096..0e86e1d 100644 --- a/logicGates/logicGates.js +++ b/logicGates/logicGates.js @@ -1,6 +1,4 @@ -// cc19 logicGates - -/* +/* cc19 logicGates * For this coding challenge you will be recreating low level logic gates. * You will first create the NAND function and then you will create * NOT, OR, AND, and XOR all using the NAND function that you created. @@ -46,7 +44,7 @@ console.log('NOT') console.log(NOT(true)); // ---> 0 console.log(NOT(false)); // ---> 1 -// AND +// phi AND psi // T && T ---> T // T && F ---> F // F && T ---> F @@ -65,7 +63,7 @@ console.log(AND(false, true)); // ---> 0 console.log(AND(false, false)); // ---> 0 -// INclusive OR +// INclusive OR: phi OR psi // T || T ---> T // T || F ---> T // F || T ---> T @@ -84,7 +82,7 @@ console.log(OR(false, true)); // ---> 1 console.log(OR(false, false)); // ---> 0 -// EXclusive OR +// EXclusive OR: phi XOR psi // T X T ---> F // T X F ---> T // F X T ---> T From e3fb9dfdc4b6ee8e82364760ff739609897ea96a Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 12:46:49 -0400 Subject: [PATCH 214/523] =?UTF-8?q?cc19=20logicGates=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logicGates/logicGates.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/logicGates/logicGates.js b/logicGates/logicGates.js index 0e86e1d..52894de 100644 --- a/logicGates/logicGates.js +++ b/logicGates/logicGates.js @@ -83,10 +83,10 @@ console.log(OR(false, false)); // ---> 0 // EXclusive OR: phi XOR psi -// T X T ---> F -// T X F ---> T -// F X T ---> T -// F X F ---> F +// T XOR T ---> F +// T XOR F ---> T +// F XOR T ---> T +// F XOR F ---> F const XOR = (x, y) => { // Do not use ||, &&, or ! // You can use any of the functions that you have already written From 59bb894e7ffbcd4fccbad084d40f36c179a4c642 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 14:07:21 -0400 Subject: [PATCH 215/523] fixed with Tai's help :D --- rotateImage/rotateImage.js | 69 +++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/rotateImage/rotateImage.js b/rotateImage/rotateImage.js index 69a4c05..206c18d 100644 --- a/rotateImage/rotateImage.js +++ b/rotateImage/rotateImage.js @@ -14,37 +14,58 @@ const rotateImage = (arr) => { const len = arr.length; rotation = Array(len).fill().map(()=> []); for (let col = 0; col < len; col++) { - for (let row = 0; row < len; row ++) { + for (let row = len - 1; row >= 0; row--) { rotation[col].push(arr[row][col]); } } return rotation; } + + + + + + + + // 10x10 array -console.log(rotateImage([ - [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], - [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], - [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], - [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], - [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], - [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], - [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], - [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], - [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], - [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] -] -)); +// console.log(rotateImage([ +// [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], +// [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], +// [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], +// [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], +// [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], +// [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], +// [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], +// [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], +// [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], +// [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] +// ] +// )); // 4x4 array console.log(rotateImage([ [ 0, 1, 2, 3 ], - [ 0, 1, 2, 3 ], - [ 0, 1, 2, 3 ], - [ 0, 1, 2, 3 ] + [ 4, 5, 6, 7 ], + [ 8, 9, 0, 1 ], + [ 2, 3, 4, 5 ] ] )); +[ + [ 2, 8, 4, 0 ], + [ 3, 9, 5, 1 ], + [ 4, 0, 6, 2 ], + [ 5, 1, 7, 3 ] ] + +[ +[ 2, 8, 4, 0 ], +[ 3, 9, 5, 1 ], +[ 4, 0, 6, 2 ], +[ 5, 1, 7, 3 ] ] + + // Not quite const rotateImageInPlace = (arr) => { const len = arr.length; @@ -58,13 +79,13 @@ const rotateImageInPlace = (arr) => { } // 4x4 array -console.log(rotateImageInPlace([ - [ 0, 1, 2, 3 ], - [ 0, 1, 2, 3 ], - [ 0, 1, 2, 3 ], - [ 0, 1, 2, 3 ] -] -)); +// console.log(rotateImageInPlace([ +// [ 0, 1, 2, 3 ], +// [ 0, 1, 2, 3 ], +// [ 0, 1, 2, 3 ], +// [ 0, 1, 2, 3 ] +// ] +// )); /* INPUT: (9x9 image matrix) From 387eb3c8e6cb30051146561c4b3953e75ec93fe0 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 3 Aug 2017 14:07:57 -0400 Subject: [PATCH 216/523] =?UTF-8?q?cc18=20-=20rotateImage=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rotateImage/Tai_solution.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 rotateImage/Tai_solution.js diff --git a/rotateImage/Tai_solution.js b/rotateImage/Tai_solution.js new file mode 100644 index 0000000..d525402 --- /dev/null +++ b/rotateImage/Tai_solution.js @@ -0,0 +1,35 @@ +// Given an image represented by an NxN matrix, where each pixel in the image is an integer from 0 - 9, +// write a method to rotate the image by 90 degrees. Can you do this in place? + +const rotateImage = (arr) => { + const len = arr.length; + for (let i = 0; i < len / 2; i++) { + for (let j = i; j < len - i - 1; j++) { + let bucket = arr[i][j]; + arr[i][j] = arr[j][len - i - 1]; + arr[j][len - i - 1] = arr[len - i - 1][len - j - 1]; + arr[len - i - 1][len - j - 1] = arr[len - j - 1][i]; + arr[len - j - 1][i] = bucket; + } + } + return arr; +}; + +const image = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 0, 1, 2], + [3, 4, 5, 6], +]; +console.log(' '); +console.log(rotateImage(image)); +console.log(rotateImage(image)); +console.log(rotateImage(image)); +console.log(rotateImage(image)); +// create a holding variable +// using two for loops + +// [[4, 8, 2, 6], +// [3, 7, 1, 5], +// [2, 6, 0, 4], +// [1, 5, 9, 3]] From 3d2ecd52198edb9cfbc7c985e825647d29e1d44b Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 4 Aug 2017 12:00:31 -0400 Subject: [PATCH 217/523] c20 parallel --- parallel/parallel.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/parallel/parallel.js b/parallel/parallel.js index 9998dea..0296827 100644 --- a/parallel/parallel.js +++ b/parallel/parallel.js @@ -1,3 +1,5 @@ +// c20 parallel + 'use strict'; /* Implement the function parallel: @@ -38,3 +40,5 @@ * * */ + +// uhh.... From ff8e36da5595620c848c84af6b20887c35e7a579 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 4 Aug 2017 12:11:48 -0400 Subject: [PATCH 218/523] whoa --- parallel/parallel.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/parallel/parallel.js b/parallel/parallel.js index 0296827..dc55abb 100644 --- a/parallel/parallel.js +++ b/parallel/parallel.js @@ -35,10 +35,24 @@ * (results) => { * // the results array will equal ['one','two'] even though * // the second function had a shorter timeout. - console.log(results); // ['one', 'two'] + * console.log(results); // ['one', 'two'] * }); * * */ // uhh.... + +parallel( + // PARAMETER 1 + [ function(callback){ + setTimeout(function() { callback('one'); }, 200); + }, + function(callback){ + setTimeout(function(){ callback('two'); }, 100); + }], + // PARAMETER 2 - optional callback + // the results array will equal ['one','two'] even though + // the second function had a shorter timeout. + (results) => { console.log(results); } // ~~> ['one', 'two'] +); From f56dac26bcff9b4c189ff8426c9dd5472793db0b Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 4 Aug 2017 12:20:16 -0400 Subject: [PATCH 219/523] shot in the dark --- parallel/parallel.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/parallel/parallel.js b/parallel/parallel.js index dc55abb..6e86ea0 100644 --- a/parallel/parallel.js +++ b/parallel/parallel.js @@ -42,17 +42,36 @@ */ // uhh.... +const parallel = (cb, ...args) => { + return (cb(args)); +} + + +// parallel( +// // PARAMETER 1 +// [ function(callback){ +// setTimeout(function() { callback('one'); }, 200); +// }, +// function(callback){ +// setTimeout(function() { callback('two'); }, 100); +// }], +// // PARAMETER 2 - optional callback +// // the results array will equal ['one','two'] even though +// // the second function had a shorter timeout. +// (results) => { console.log(results); } // ~~> ['one', 'two'] +// ); parallel( + // PARAMETER 2 - optional callback + // the results array will equal ['one','two'] even though + // the second function had a shorter timeout. + (results) => { console.log(results); } // ~~> ['one', 'two'] + , // PARAMETER 1 [ function(callback){ setTimeout(function() { callback('one'); }, 200); }, function(callback){ - setTimeout(function(){ callback('two'); }, 100); - }], - // PARAMETER 2 - optional callback - // the results array will equal ['one','two'] even though - // the second function had a shorter timeout. - (results) => { console.log(results); } // ~~> ['one', 'two'] -); + setTimeout(function() { callback('two'); }, 100); + }] + ); From 4610d4514d882e54de0e9795e3f917930cd47d25 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 4 Aug 2017 13:41:27 -0400 Subject: [PATCH 220/523] Emily's solutions --- logicGates/logicgates.pdf | Bin 0 -> 23832 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 logicGates/logicgates.pdf diff --git a/logicGates/logicgates.pdf b/logicGates/logicgates.pdf new file mode 100644 index 0000000000000000000000000000000000000000..cd2aaaee1ac49fb59fcae1e2de9ae261c141c4e4 GIT binary patch literal 23832 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 literal 0 HcmV?d00001 From 4db735b62dd39af873d76789079920bb1d57ad6a Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 4 Aug 2017 13:41:40 -0400 Subject: [PATCH 221/523] =?UTF-8?q?cc19=20-=20logicGates=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logicGates/logicGates.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/logicGates/logicGates.js b/logicGates/logicGates.js index 52894de..c719725 100644 --- a/logicGates/logicGates.js +++ b/logicGates/logicGates.js @@ -9,6 +9,11 @@ * All functions should return a 1 for true and a 0 for false. */ +/* TODO: + 1. refactor with ternary operator + 2. complete each with NAND +*/ + // phi AND psi // (T && T) ---> T // (T && F) ---> F @@ -34,8 +39,8 @@ console.log(NAND(false, false)); // ---> 1 // Not operator -// !T --> F -// !F --> T +// !T ---> F +// !F ---> T const NOT = (n) => { // Do not use !, &&, or || return (NAND(n, n)); From cd2b33f10f4134508f72e7c0ec2680397bce44c1 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 4 Aug 2017 13:41:56 -0400 Subject: [PATCH 222/523] cc20 - parralel: w.i.p. --- parallel/parallel.js | 60 +++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/parallel/parallel.js b/parallel/parallel.js index 6e86ea0..1af3973 100644 --- a/parallel/parallel.js +++ b/parallel/parallel.js @@ -4,17 +4,17 @@ /* Implement the function parallel: * - * Parallel has two parameters, an array of asynchronous functions (tasks) and a callback. - * Each of the tasks takes a callback and invokes that callback when complete. + * Parallel has two parameters, an array of asynchronous functions (tasks) and a callback. - OKAY √ + * Each of the tasks takes a callback and invokes that callback when complete. - OKAY √ * - * The callback passed to parallel is then performed on the results of the callbacks of the tasks. + * The callback passed to parallel is then performed on the results of the callbacks of the tasks. - Umm, okay? * - * The order of these results should be the same as the order of the tasks. - * It is important to note that this is not the order in which the tasks return, - * but the order in which they are passed to parallel. + * The order of these results should be the same as the order of the tasks. - Okay... + * It is important to note that this is not the order in which the tasks return, - I see the Timeout durations + * but the order in which they are passed to parallel. - Alright... * * Once all the callbacks of the tasks are returned, parallel should invoke the callback - * on the results array. + * on the results array. - OKAY√ * * * Example: @@ -42,36 +42,40 @@ */ // uhh.... -const parallel = (cb, ...args) => { +const parallel = (...args, cb) => { return (cb(args)); } +// const parallel = (cb, ...args) => { +// return (cb(args)); +// } -// parallel( -// // PARAMETER 1 -// [ function(callback){ -// setTimeout(function() { callback('one'); }, 200); -// }, -// function(callback){ -// setTimeout(function() { callback('two'); }, 100); -// }], -// // PARAMETER 2 - optional callback -// // the results array will equal ['one','two'] even though -// // the second function had a shorter timeout. -// (results) => { console.log(results); } // ~~> ['one', 'two'] -// ); parallel( - // PARAMETER 2 - optional callback - // the results array will equal ['one','two'] even though - // the second function had a shorter timeout. - (results) => { console.log(results); } // ~~> ['one', 'two'] - , // PARAMETER 1 [ function(callback){ setTimeout(function() { callback('one'); }, 200); }, function(callback){ setTimeout(function() { callback('two'); }, 100); - }] - ); + }], + // PARAMETER 2 - optional callback + // the results array will equal ['one','two'] even though + // the second function had a shorter timeout. + (results) => { console.log(results); } // ~~> ['one', 'two'] +); + +// parallel( +// // PARAMETER 2 - optional callback +// // the results array will equal ['one','two'] even though +// // the second function had a shorter timeout. +// (results) => { console.log(results); } // ~~> ['one', 'two'] +// , +// // PARAMETER 1 +// [ function(callback){ +// setTimeout(function() { callback('one'); }, 200); +// }, +// function(callback){ +// setTimeout(function() { callback('two'); }, 100); +// }] +// ); From 28b2a462cf4294a696552d99cd654862c0bef03a Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 7 Aug 2017 12:04:21 -0400 Subject: [PATCH 223/523] merge --- {queueStack/reverseCase => reverseCase}/reverseCase.js | 0 {queueStack/reverseCase => reverseCase}/solution.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {queueStack/reverseCase => reverseCase}/reverseCase.js (100%) rename {queueStack/reverseCase => reverseCase}/solution.js (100%) diff --git a/queueStack/reverseCase/reverseCase.js b/reverseCase/reverseCase.js similarity index 100% rename from queueStack/reverseCase/reverseCase.js rename to reverseCase/reverseCase.js diff --git a/queueStack/reverseCase/solution.js b/reverseCase/solution.js similarity index 100% rename from queueStack/reverseCase/solution.js rename to reverseCase/solution.js From f32953bc02a83a779a768be56b0782bb6cecfcb3 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 7 Aug 2017 12:04:34 -0400 Subject: [PATCH 224/523] cc20 parallel --- parallel/parallel.js | 52 ++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/parallel/parallel.js b/parallel/parallel.js index 1af3973..0837b4f 100644 --- a/parallel/parallel.js +++ b/parallel/parallel.js @@ -41,41 +41,45 @@ * */ -// uhh.... -const parallel = (...args, cb) => { - return (cb(args)); -} +// // uhh.... +// const parallel = (...args, cb) => { +// return (cb(args)); +// } // const parallel = (cb, ...args) => { // return (cb(args)); // } +const parallel = (cb, ...args) => { + return (args(cb)); +} -parallel( - // PARAMETER 1 - [ function(callback){ - setTimeout(function() { callback('one'); }, 200); - }, - function(callback){ - setTimeout(function() { callback('two'); }, 100); - }], - // PARAMETER 2 - optional callback - // the results array will equal ['one','two'] even though - // the second function had a shorter timeout. - (results) => { console.log(results); } // ~~> ['one', 'two'] -); // parallel( -// // PARAMETER 2 - optional callback -// // the results array will equal ['one','two'] even though -// // the second function had a shorter timeout. -// (results) => { console.log(results); } // ~~> ['one', 'two'] -// , // // PARAMETER 1 // [ function(callback){ // setTimeout(function() { callback('one'); }, 200); // }, // function(callback){ // setTimeout(function() { callback('two'); }, 100); -// }] -// ); +// }], +// // PARAMETER 2 - optional callback +// // the results array will equal ['one','two'] even though +// // the second function had a shorter timeout. +// (results) => { console.log(results); } // ~~> ['one', 'two'] +// ); + +parallel( + // PARAMETER 2 - optional callback + // the results array will equal ['one','two'] even though + // the second function had a shorter timeout. + (results) => { console.log(results); } // ~~> ['one', 'two'] + , + // PARAMETER 1 + [ function(callback){ + setTimeout(function() { callback('one'); }, 200); + }, + function(callback){ + setTimeout(function() { callback('two'); }, 100); + }] + ); From ce0ca056187f4cdea732db441d43652943921d02 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 7 Aug 2017 12:16:00 -0400 Subject: [PATCH 225/523] cc20 - rPS: rough --- rockPaperScissors/rockPaperScissors.js | 42 +++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/rockPaperScissors/rockPaperScissors.js b/rockPaperScissors/rockPaperScissors.js index 9f54ca2..9057fe2 100644 --- a/rockPaperScissors/rockPaperScissors.js +++ b/rockPaperScissors/rockPaperScissors.js @@ -1,3 +1,5 @@ +// cc21 rockPaperScissor + /* * * Write a function that generates every sequence of throws a single * * player could throw over a three-round game of rock-paper-scissors. @@ -12,4 +14,42 @@ const rockPaperScissors = () => { // TODO: your solution here -}; \ No newline at end of file + const hand = {0: 'rock', + 1: 'paper', + 2: 'scissor'} + const hand = ['rock', 'paper', 'scissor'] + +}; + + + +const allAnagrams = (str) => { + + if (str.length < 2) return str; + + const result = []; + + for (let i = 0; i < str.length; i++) { + let firstLetter = str[i]; + let restOfString = str.slice(0, i) + str.slice(i + 1, str.length); + + for (let sub of allAnagrams(restOfString)) { + result.push(firstLetter + sub); + } + } + return result; +} + + +const allAnagrams = (str, start = '') => { + if (str.length === 1) return [start + str]; + const anagrams = []; + + for (let i = 0; i < str.length; i++) { + const result = allAnagrams(str.substr(0, i) + str.substr(i + 1), str[i]); + for (let j = 0; j < result.length; j++) { + anagrams.push(start + result[j]); + } + } + return anagrams; +}; From cffccbdee88406bb26fdf4c776a67363f4342d26 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 7 Aug 2017 12:26:26 -0400 Subject: [PATCH 226/523] cc21 rockPaperScissor --- rockPaperScissors/rockPaperScissors.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rockPaperScissors/rockPaperScissors.js b/rockPaperScissors/rockPaperScissors.js index 9057fe2..e4511c9 100644 --- a/rockPaperScissors/rockPaperScissors.js +++ b/rockPaperScissors/rockPaperScissors.js @@ -14,10 +14,12 @@ const rockPaperScissors = () => { // TODO: your solution here - const hand = {0: 'rock', - 1: 'paper', - 2: 'scissor'} - const hand = ['rock', 'paper', 'scissor'] + // const hand = {0: 'rock', + // 1: 'paper', + // 2: 'scissor'} + const hand = ['rock', 'paper', 'scissor'] // hand.length = 3 + let rounds = 3 + const totalPossibleCombos = hand.length ** rounds }; From 58ee79975fd59ba2670f8025bab6447a2e0d7d83 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 7 Aug 2017 12:59:27 -0400 Subject: [PATCH 227/523] cc21 rockPaperScissor - w.i.p. --- rockPaperScissors/rockPaperScissors.js | 80 +++++++++++++++----------- 1 file changed, 48 insertions(+), 32 deletions(-) diff --git a/rockPaperScissors/rockPaperScissors.js b/rockPaperScissors/rockPaperScissors.js index e4511c9..e9e9371 100644 --- a/rockPaperScissors/rockPaperScissors.js +++ b/rockPaperScissors/rockPaperScissors.js @@ -12,46 +12,62 @@ * ...etc... * */ -const rockPaperScissors = () => { - // TODO: your solution here - // const hand = {0: 'rock', - // 1: 'paper', - // 2: 'scissor'} - const hand = ['rock', 'paper', 'scissor'] // hand.length = 3 - let rounds = 3 - const totalPossibleCombos = hand.length ** rounds +// const rockPaperScissors = () => { +// // TODO: your solution here +// // const hand = {0: 'rock', +// // 1: 'paper', +// // 2: 'scissor'} +// const hand = ['rock', 'paper', 'scissor'] // hand.length = 3 +// let rounds = 3 +// const totalPossibleCombos = hand.length ** rounds // 27 ~~~> (n terms)**3 +// +// }; -}; - - - -const allAnagrams = (str) => { - - if (str.length < 2) return str; +const test = (arr) => { const result = []; - for (let i = 0; i < str.length; i++) { - let firstLetter = str[i]; - let restOfString = str.slice(0, i) + str.slice(i + 1, str.length); + for (let i = 0; i < arr.length; i++) { + let firstElement = arr[i]; + let restOfArray = arr.slice(0, i) + arr.slice(i + 1, arr.length); - for (let sub of allAnagrams(restOfString)) { - result.push(firstLetter + sub); + for (let sub of test(restOfArray)) { + result.push(firstElement, sub); } } return result; } +console.log(test(['rock', 'paper', 'scissor'])); -const allAnagrams = (str, start = '') => { - if (str.length === 1) return [start + str]; - const anagrams = []; - - for (let i = 0; i < str.length; i++) { - const result = allAnagrams(str.substr(0, i) + str.substr(i + 1), str[i]); - for (let j = 0; j < result.length; j++) { - anagrams.push(start + result[j]); - } - } - return anagrams; -}; +// +// const allAnagrams = (str) => { +// +// if (str.length < 2) return str; +// +// const result = []; +// +// for (let i = 0; i < str.length; i++) { +// let firstLetter = str[i]; +// let restOfString = str.slice(0, i) + str.slice(i + 1, str.length); +// +// for (let sub of allAnagrams(restOfString)) { +// result.push(firstLetter + sub); +// } +// } +// return result; +// } +// +// +// const allAnagrams = (str, start = '') => { +// if (str.length === 1) return [start + str]; +// const anagrams = []; +// +// for (let i = 0; i < str.length; i++) { +// const result = allAnagrams(str.substr(0, i) + str.substr(i + 1), str[i]); +// for (let j = 0; j < result.length; j++) { +// anagrams.push(start + result[j]); +// } +// } +// return anagrams; +// }; From c6570c1fcc17542b08ea0b40e2a0964364da66f5 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 7 Aug 2017 13:27:53 -0400 Subject: [PATCH 228/523] c20 parallel Tais solution --- parallel/Tais_Solution.js | 97 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 parallel/Tais_Solution.js diff --git a/parallel/Tais_Solution.js b/parallel/Tais_Solution.js new file mode 100644 index 0000000..a894776 --- /dev/null +++ b/parallel/Tais_Solution.js @@ -0,0 +1,97 @@ +// const parallel = (arrayOfFunctions, cb) => { +// // create a new array +// // get length of functionsArray +// // use forEach with arrow function param (func, i) +// // invoke each func with arrow function param (value) +// // subtract one from functionsArray length +// // if funArray.length === 0, cb(new array) +// +// const values = []; +// let remainingItems = arrayOfFunctions.length; +// arrayOfFunctions.forEach((func, i) => { +// func((value) => { +// values[i] = values; +// remainingItems--; +// if (remainingItems === 0) cb(values); +// }); +// }); +// }; + + +'use strict'; + +/* Implement the function parallel: + * + * Parallel has two parameters, an array of asynchronous functions (tasks) and a callback. + * Each of the tasks takes a callback and invokes that callback when complete. + * + * The callback passed to parallel is then performed on the results of the callbacks of the tasks. + * + * The order of these results should be the same as the order of the tasks. + * It is important to note that this is not the order in which the tasks return, + * but the order in which they are passed to parallel. + * + * Once all the callbacks of the tasks are returned, parallel should invoke the callback + * on the results array. + * + * + * Example: + * + * parallel([ + * function(callback){ + * setTimeout(function(){ + * callback('one'); + * }, 200); + * }, + * function(callback){ + * setTimeout(function(){ + * callback('two'); + * }, 100); + * } + * ], + * // optional callback + * (results) => { + * // the results array will equal ['one','two'] even though + * // the second function had a shorter timeout. + console.log(results); // ['one', 'two'] + * }); + * + * + */ + +const parallel = (functions, cb) => { + // create a new array + // get length of functionsArray + // use forEach with arrow function params (func, i) + // invoke each func with arrow function param (value) + // subtract one from functionsArrayLength + // if functionsArrayLength === 0, cb(newArray) + const values = []; + let remainingItems = functions.length; + functions.forEach((func, i) => { + func((value) => { + values[i] = value; + remainingItems--; + if (remainingItems === 0) cb(values); + }); + }); +}; + +const paraArr = [ + function(callback){ + setTimeout(function(){ + callback('one'); + }, 200); + }, + function(callback){ + setTimeout(function(){ + callback('two'); + }, 100); + } +]; +const cbFun = (results) => { + // the results array will equal ['one','two'] even though + // the second function had a shorter timeout. + console.log(results); // ['one', 'two'] +}; +parallel(paraArr, cbFun); From b2979994d0c7cd82fc2635cb680140b76cd9dc34 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 8 Aug 2017 11:58:10 -0400 Subject: [PATCH 229/523] cc21 rockPaperScissor w.i.p. --- rockPaperScissors/rockPaperScissors.js | 32 -------------------------- 1 file changed, 32 deletions(-) diff --git a/rockPaperScissors/rockPaperScissors.js b/rockPaperScissors/rockPaperScissors.js index e9e9371..ce715fd 100644 --- a/rockPaperScissors/rockPaperScissors.js +++ b/rockPaperScissors/rockPaperScissors.js @@ -39,35 +39,3 @@ const test = (arr) => { } console.log(test(['rock', 'paper', 'scissor'])); - -// -// const allAnagrams = (str) => { -// -// if (str.length < 2) return str; -// -// const result = []; -// -// for (let i = 0; i < str.length; i++) { -// let firstLetter = str[i]; -// let restOfString = str.slice(0, i) + str.slice(i + 1, str.length); -// -// for (let sub of allAnagrams(restOfString)) { -// result.push(firstLetter + sub); -// } -// } -// return result; -// } -// -// -// const allAnagrams = (str, start = '') => { -// if (str.length === 1) return [start + str]; -// const anagrams = []; -// -// for (let i = 0; i < str.length; i++) { -// const result = allAnagrams(str.substr(0, i) + str.substr(i + 1), str[i]); -// for (let j = 0; j < result.length; j++) { -// anagrams.push(start + result[j]); -// } -// } -// return anagrams; -// }; From 41379c701ea1a141fe0e432c1973f2ddbc03e273 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 8 Aug 2017 12:04:02 -0400 Subject: [PATCH 230/523] resuscitated after merged/erased --- reverseCase/pdk_reverseCase.js | 53 ++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 reverseCase/pdk_reverseCase.js diff --git a/reverseCase/pdk_reverseCase.js b/reverseCase/pdk_reverseCase.js new file mode 100644 index 0000000..4cafa7f --- /dev/null +++ b/reverseCase/pdk_reverseCase.js @@ -0,0 +1,53 @@ +// I don't know why this got merge/erased, but this is my work: + +/* + * Write a function that reverses the case of each letter in the strings that it receives. + * Example: 'Hello World' -> 'hELLO wORLD' + * Assume that each string will contain only spaces and letters. + */ + +const reverseCase = function (str) { + // declare an array to house individual string letters or spaces in word/sentence order + const letters = []; + // declare a variable which will be used to reconstructed string + let caseConvertedString; + + // examine each letter in the string + for (let i = 0; i < str.length; i++) { + // uppercase or lowercase or a space? + // if a space, push space into temp holding array (if not a space, it's a letter) + if (str[i] === ' ') { + letters.push(str[i]); + // if already Upper Case, push lower Case version of letter into holding array + } else if (str[i] === str[i].toUpperCase()) { + letters.push(str[i].toLowerCase()) + // if not space and not already Upper Case, push Upper Case version of letter to holding array + } else letters.push(str[i].toUpperCase()) + } + // zip up the array of letters and spaces into a string + caseConvertedString = letters.join(''); + return caseConvertedString; +} + +const testCase1 = 'Hello World' +console.log(reverseCase(testCase1)); // ---> hELLO wORLD +const testCase2 = 'Fsdfsdf ESDFSDFdfsdfsdfsdfdsf'; +console.log(reverseCase(testCase2)); // ---> fSDFSDF esdfsdfDFSDFSDFSDFDSF +// will it handle periods? +const testCase3 = 'The quick brown Mr. Fox jumped over the lazy Mr. Dog.'; +console.log(reverseCase(testCase3)); // ---> tHE QUICK BROWN mR. fOX JUMPED OVER THE LAZY mR. dOG. + +// // Latoyya's solution +// const reverseString = (str) => { +// let newString = ''; +// for (let i = 0; i < str.length; i++) { +// if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) { +// newString += str.charAt(i).toLowerCase(); +// } else { +// newString += str.charAt(i).toUpperCase(); +// } +// } +// return newString; +// }; +// console.log(reverseString('Hello World')); +// console.log(reverseString('Hello World My NamE is LAtoyYa SmitH')); From 71a237d0f0a93d48a91e24304999df3b543d7c75 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 8 Aug 2017 12:27:00 -0400 Subject: [PATCH 231/523] cc22 quickSort w.i.p. --- quickSort/quickSort.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickSort/quickSort.js b/quickSort/quickSort.js index 7af4064..7e52d71 100644 --- a/quickSort/quickSort.js +++ b/quickSort/quickSort.js @@ -1,4 +1,4 @@ - +// cc22 quickSort /* * Implement the quick sort sorting algorithm. Assume the input is an array of integers. * https://en.wikipedia.org/wiki/Quicksort @@ -6,4 +6,4 @@ */ const quickSort = (nums) => { -}; \ No newline at end of file +}; From 73d372fc8ca8f8c45d0913b3289cf3d3b99ffe33 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 8 Aug 2017 12:27:13 -0400 Subject: [PATCH 232/523] cc21 rockPapSciss w.i.p. --- rockPaperScissors/rockPaperScissors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rockPaperScissors/rockPaperScissors.js b/rockPaperScissors/rockPaperScissors.js index ce715fd..5e26c4a 100644 --- a/rockPaperScissors/rockPaperScissors.js +++ b/rockPaperScissors/rockPaperScissors.js @@ -28,8 +28,8 @@ const test = (arr) => { const result = []; for (let i = 0; i < arr.length; i++) { - let firstElement = arr[i]; - let restOfArray = arr.slice(0, i) + arr.slice(i + 1, arr.length); + let firstElement = arr.shift(); + let restOfArray = arr for (let sub of test(restOfArray)) { result.push(firstElement, sub); From 651be13e02450a9fe7ca501226f4d6541635c78c Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Tue, 8 Aug 2017 13:29:37 -0400 Subject: [PATCH 233/523] cc21 rockPaperScissor solution lecture --- rockPaperScissors/Tai_solution.js | 60 ++++++++++++++++++++++++++ rockPaperScissors/rockPaperScissors.js | 7 ++- 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 rockPaperScissors/Tai_solution.js diff --git a/rockPaperScissors/Tai_solution.js b/rockPaperScissors/Tai_solution.js new file mode 100644 index 0000000..07efa52 --- /dev/null +++ b/rockPaperScissors/Tai_solution.js @@ -0,0 +1,60 @@ +// triple for loop vs recursion + +/* + * * Write a function that generates every sequence of throws a single + * * player could throw over a three-round game of rock-paper-scissors. + * * + * * Your output should look something like: + * * [["rock", "rock", "rock"], + * * ["rock", "rock", "paper"], + * * ["rock", "rock", "scissor"], + * * ["rock", "paper", "rock"], + * ...etc... + * */ + +const rockPaperScissorsLoop = () => { + // TODO: your solution here + // we need an answer container + // we need an array of strings r,p,s + // we need to iterate the first part of the array ['scissors',] + // inside the for loop, we need to iterate the second part of the array[..., 'scissors',] + // inside the second for loop, we need to iterate the third part of the array [..., ..., 'scissors'] + // once we generate all three, then we need to push to answers + //after forloop tango, return array + // so when O(n^3) is written, n is arrayOfStrings.length + const answer = []; + const choice = ['rock', 'paper', 'scissors']; + for (let i = 0; i < choice.length; i++) { + for (let j = 0; j < choice.length; j++) { + for (let k = 0; k < choice.length; k++) { + answer.push([choice[i], choice[j], choice[k]]); + } + } + } + return answer; +}; + +console.log(rockPaperScissorsLoop()); + + + + +const rockPaperScissorsRecurse = (rounds) => { + const results = []; + const choices = ['scissors', 'rock', 'paper']; + const findChoices = (roundsLeft, roundsPlayed) => { + if (roundsLeft === 0) { + results.push(roundsPlayed); + return; + } + for (let i = 0; i < choices.length; i++) { + const choice = choices[i]; + findChoices(roundsLeft - 1, roundsPlayed.concat(choice)); + } + }; + findChoices(rounds, []); + + return results; +}; + +console.log(rockPaperScissorsRecurse(3)); diff --git a/rockPaperScissors/rockPaperScissors.js b/rockPaperScissors/rockPaperScissors.js index 5e26c4a..a5fdcd8 100644 --- a/rockPaperScissors/rockPaperScissors.js +++ b/rockPaperScissors/rockPaperScissors.js @@ -28,8 +28,11 @@ const test = (arr) => { const result = []; for (let i = 0; i < arr.length; i++) { - let firstElement = arr.shift(); - let restOfArray = arr + // let firstElement = arr[i]; + let firstElement = []; + firstElement.push(arr[i]); + + let restOfArray = arr.slice(i + 1, arr.length); for (let sub of test(restOfArray)) { result.push(firstElement, sub); From 27969ed406186eee910c9ce60b2762dd4f80870f Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 9 Aug 2017 11:58:56 -0400 Subject: [PATCH 234/523] cc22 quickSort: close... --- quickSort/quickSort.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/quickSort/quickSort.js b/quickSort/quickSort.js index 7e52d71..c43fac6 100644 --- a/quickSort/quickSort.js +++ b/quickSort/quickSort.js @@ -5,5 +5,27 @@ * https://www.khanacademy.org/computing/computer-science/algorithms#quick-sort */ const quickSort = (nums) => { + if (nums.length < 2) { + return nums; + } + // console.log(nums) + const pivot = nums[0] + let lessThan = []; + let greaterThan = []; + + for (let i = 0; i < nums.length; i++) { + if (nums[i] < pivot) { + lessThan.push(nums[i]); + // console.log('less than array: ', lessThan) + } else { + greaterThan.push(nums[i]); + // console.log('GRTR than array: ', greaterThan) + } + }; + return quickSort(lessThan).concat(pivot, quickSort(greaterThan)); }; + +// TEST SUITE +// console.log(quickSort([ 9, 8, 7, 555, 632, 345, 4, 3, 2, 1])); +console.log(quickSort([ 9, 8, 7, 555, 632 ])); From 6fa7c604c37e25a5328a63a8da0a0b977c0ba99a Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 9 Aug 2017 12:20:48 -0400 Subject: [PATCH 235/523] cc22 quickSort: w.i.p. --- quickSort/quickSort.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/quickSort/quickSort.js b/quickSort/quickSort.js index c43fac6..6c81845 100644 --- a/quickSort/quickSort.js +++ b/quickSort/quickSort.js @@ -5,27 +5,32 @@ * https://www.khanacademy.org/computing/computer-science/algorithms#quick-sort */ const quickSort = (nums) => { - if (nums.length < 2) { + if (nums.length < 2) { // BASE CASE return nums; } - // console.log(nums) - - const pivot = nums[0] - let lessThan = []; - let greaterThan = []; + // const pivot = nums[Math.floor(nums.length / 2)], + const pivot = nums[0], + lessThan = [], + greaterThan = []; for (let i = 0; i < nums.length; i++) { if (nums[i] < pivot) { lessThan.push(nums[i]); // console.log('less than array: ', lessThan) - } else { - greaterThan.push(nums[i]); + } else greaterThan.push(nums[i]); // console.log('GRTR than array: ', greaterThan) - } }; - return quickSort(lessThan).concat(pivot, quickSort(greaterThan)); + // console.log(lessThan, pivot, greaterThan) + return quickSort(lessThan).concat(quickSort(greaterThan)); }; + // TEST SUITE + +// const x = [1,2,3], +// y = 4 +// z = [5,6,7]; +// console.log(x.concat(y, z)); + // console.log(quickSort([ 9, 8, 7, 555, 632, 345, 4, 3, 2, 1])); -console.log(quickSort([ 9, 8, 7, 555, 632 ])); +console.log(quickSort([ 4, 5, 6, 3, 2 ])); From 9d77d24b60948aa867a1cd1a845876352574fb60 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 9 Aug 2017 12:31:04 -0400 Subject: [PATCH 236/523] =?UTF-8?q?cc22=20quickSort=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quickSort/quickSort.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/quickSort/quickSort.js b/quickSort/quickSort.js index 6c81845..d8eca4f 100644 --- a/quickSort/quickSort.js +++ b/quickSort/quickSort.js @@ -5,23 +5,21 @@ * https://www.khanacademy.org/computing/computer-science/algorithms#quick-sort */ const quickSort = (nums) => { - if (nums.length < 2) { // BASE CASE + // BASE CASE + if (nums.length < 2) { return nums; - } - // const pivot = nums[Math.floor(nums.length / 2)], + } /* v */ const pivot = nums[0], lessThan = [], greaterThan = []; - - for (let i = 0; i < nums.length; i++) { + /* v */ + for (let i = 1; i < nums.length; i++) { if (nums[i] < pivot) { lessThan.push(nums[i]); - // console.log('less than array: ', lessThan) } else greaterThan.push(nums[i]); - // console.log('GRTR than array: ', greaterThan) }; - // console.log(lessThan, pivot, greaterThan) - return quickSort(lessThan).concat(quickSort(greaterThan)); + // Binary tree recursion? BigO((n^2)^2) + return quickSort(lessThan).concat(pivot, quickSort(greaterThan)); }; @@ -32,5 +30,5 @@ const quickSort = (nums) => { // z = [5,6,7]; // console.log(x.concat(y, z)); -// console.log(quickSort([ 9, 8, 7, 555, 632, 345, 4, 3, 2, 1])); -console.log(quickSort([ 4, 5, 6, 3, 2 ])); +console.log(quickSort([ 9, 8, 7, 555, 632, 345, 4, 3, 2, 1])); +console.log(quickSort([ 4, 6, 5, 3, 2 ])); From 8a6f5e14ff60a4cf442fdb6f29572413d65b9ee6 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 9 Aug 2017 12:36:09 -0400 Subject: [PATCH 237/523] cc23 selectionSort --- selectionSort/selectionSort.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/selectionSort/selectionSort.js b/selectionSort/selectionSort.js index feefe83..bf48b10 100644 --- a/selectionSort/selectionSort.js +++ b/selectionSort/selectionSort.js @@ -1,4 +1,4 @@ -/* +/* cc23 selectionSort * Sort an array of numbers using selection sort. * https://en.wikipedia.org/wiki/Selection_sort * https://www.khanacademy.org/computing/computer-science/algorithms/sorting-algorithms/a/sorting @@ -8,4 +8,4 @@ const selectionSort = (arr) => { -}; \ No newline at end of file +}; From bdf9b92909764a6d4dd585feb9eeef89046ebc2e Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 9 Aug 2017 12:50:02 -0400 Subject: [PATCH 238/523] =?UTF-8?q?cc23=20selectionSort=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- selectionSort/selectionSort.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/selectionSort/selectionSort.js b/selectionSort/selectionSort.js index bf48b10..19ab67b 100644 --- a/selectionSort/selectionSort.js +++ b/selectionSort/selectionSort.js @@ -7,5 +7,20 @@ */ const selectionSort = (arr) => { - + const sorted = Array.from(arr); + let minIndex, i, j; + for (i = 0; i < sorted.length; i++) { + minIndex = i; + for (j = i; j < sorted.length; j++) { + if (sorted[j] < sorted[minIndex]) { + minIndex = j; + } + } + [sorted[i], sorted[minIndex]] = [sorted[minIndex], sorted[i]]; + } + return sorted; }; + + +// TEST SUITE +console.log(selectionSort([9, 7, 8, 5, 6, 4, 5, 2, 3, 1])); From a7475e79dfe832645098edec924eb824c919b7ee Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 9 Aug 2017 13:44:32 -0400 Subject: [PATCH 239/523] =?UTF-8?q?cc22=20quickSort=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quickSort/quickSort.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickSort/quickSort.js b/quickSort/quickSort.js index d8eca4f..d93cfc9 100644 --- a/quickSort/quickSort.js +++ b/quickSort/quickSort.js @@ -28,7 +28,7 @@ const quickSort = (nums) => { // const x = [1,2,3], // y = 4 // z = [5,6,7]; -// console.log(x.concat(y, z)); +// console.log(x.concat(y, z)); // ~~~> [ 1, 2, 3, 4, 5, 6, 7 ] console.log(quickSort([ 9, 8, 7, 555, 632, 345, 4, 3, 2, 1])); console.log(quickSort([ 4, 6, 5, 3, 2 ])); From e8b9f0f3d87ec7ea210ec67f39f8445600cb05e5 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Wed, 9 Aug 2017 13:44:45 -0400 Subject: [PATCH 240/523] cc22 quickSort - Tai's solution --- quickSort/Tai_solution.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 quickSort/Tai_solution.js diff --git a/quickSort/Tai_solution.js b/quickSort/Tai_solution.js new file mode 100644 index 0000000..087c19a --- /dev/null +++ b/quickSort/Tai_solution.js @@ -0,0 +1,35 @@ +// http://me.dt.in.th/page/Quicksort/ + +/* + * Implement the quick sort sorting algorithm. Assume the input is an array of integers. + * https://en.wikipedia.org/wiki/Quicksort + * https://www.khanacademy.org/computing/computer-science/algorithms#quick-sort + */ + +const quickSort = (arr) => { + // base case for recursion, if array.length is <= 1, return arr + // create lessthan array + // create gr8rthan array + // find a pivot + // for loop, sorting if arr[i] is > || <= pivot + // create answer array = [] + // return answerArray.concat(quicksort of lessthan, pivot, quicksort of greaterthan) + if (arr.length <= 1) return arr; + + const lessThan = []; + const greaterThan = []; + const pivot = arr.splice(Math.floor(Math.random() * arr.length - 1), 1); + console.log(pivot); + for (let i = arr.length - 1; i >= 0; i--) { + if (arr[i] < pivot) { + lessThan.push(arr[i]); + } else { + greaterThan.push(arr[i]); + } + } + + const c = []; + return c.concat(quickSort(lessThan), pivot, quickSort(greaterThan)); +}; + +console.log(quickSort([9, 8, 7, 6, 5, 4, 3, 2, 1])); From 9dfb0ad4c04695c90e5c0cfa4092257f4903fead Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 10 Aug 2017 12:42:54 -0400 Subject: [PATCH 241/523] pseudocode and rough start --- rotatedArray/rotatedArray.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/rotatedArray/rotatedArray.js b/rotatedArray/rotatedArray.js index ae1f0f7..f603ed6 100644 --- a/rotatedArray/rotatedArray.js +++ b/rotatedArray/rotatedArray.js @@ -1,4 +1,5 @@ -/* +/* cc24 rotatedArray + * Given a sorted array that has been rotated some number of items right or * left, i.e. [0, 1, 2, 3, 4, 5, 6, 7] might become [4, 5, 6, 7, 0, 1, 2, 3] * how can you efficiently find an element? For simplicity, you can assume @@ -13,4 +14,29 @@ * rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 100) === null * * Target time complexity: O(log(n)) - */ \ No newline at end of file + + 1) presuming a sorted & offset array + 2) search for the first index pair (arr[n] and arr[n+1]) where arr[n] > arr[n+1] + 3) arr[n] is the high value of the range + 4) arr[n+1] is the low value of the range + 5) query integer is outside range, return null + 5) index position of arr[n+1] is the offset where [n+1] minus offset = 0 + 6) not sure how to quickly return +*/ + +const rotatedArraySearch = (arr, queryNum) => { + let i, high, low, highIndex, lowIndex; + // search for the first pair where arr[n] > arr[n+1] + for (let i = 0; i < arr.length; i++) { + if (arr[i] > arr[i + 1]) { + [high, low, highIndex, lowIndex] = [arr[i], arr[i + 1], i, i + 1]; + } + }; + // console.log(`HI value: ${high}, is at index: ${highIndex}\nLO value: ${low}, is at index: ${lowIndex}`); + if (queryNum >= low && high >= queryNum) { + console.log( 'poop'); + } else { return null; } +}; + +// TEST SUITE +rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], -6); From d51c16e27bb22b47e99c5756e40feda1a1f35ca8 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 10 Aug 2017 13:01:33 -0400 Subject: [PATCH 242/523] =?UTF-8?q?cc24=20rotatedArray=20=E2=88=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rotatedArray/rotatedArray.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/rotatedArray/rotatedArray.js b/rotatedArray/rotatedArray.js index f603ed6..73eeddc 100644 --- a/rotatedArray/rotatedArray.js +++ b/rotatedArray/rotatedArray.js @@ -21,10 +21,11 @@ 4) arr[n+1] is the low value of the range 5) query integer is outside range, return null 5) index position of arr[n+1] is the offset where [n+1] minus offset = 0 - 6) not sure how to quickly return + 6) not sure how to quickly return the index... */ const rotatedArraySearch = (arr, queryNum) => { + const len = arr.length; let i, high, low, highIndex, lowIndex; // search for the first pair where arr[n] > arr[n+1] for (let i = 0; i < arr.length; i++) { @@ -32,11 +33,30 @@ const rotatedArraySearch = (arr, queryNum) => { [high, low, highIndex, lowIndex] = [arr[i], arr[i + 1], i, i + 1]; } }; - // console.log(`HI value: ${high}, is at index: ${highIndex}\nLO value: ${low}, is at index: ${lowIndex}`); - if (queryNum >= low && high >= queryNum) { - console.log( 'poop'); - } else { return null; } + console.log(arr, queryNum) + console.log(`HI value: ${high}, is at index: ${highIndex}`) + console.log(`LO value: ${low}, is at index: ${lowIndex}`) + console.log(`TOTAL number of array elements: ${len}`); + if (!(queryNum >= low && high >= queryNum)) { + console.log(null); + } else { + if ((len - queryNum) <= lowIndex) { + console.log(arr[lowIndex - (len - queryNum)]); + return arr[lowIndex - (len - queryNum)]; + } else { + console.log(arr[len - queryNum]); + return arr[len - queryNum]; + }; + }; }; // TEST SUITE -rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], -6); +rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], -1); +rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 0); +rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 1); +rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 2); +rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 3); +rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 4); +rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 5); +rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 6); +rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 7); From 1828c9ea314013ecff8a431a398e4b52cfd62b07 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Thu, 10 Aug 2017 13:32:53 -0400 Subject: [PATCH 243/523] cc24 rotatedArray - close... --- rotatedArray/rotatedArray.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/rotatedArray/rotatedArray.js b/rotatedArray/rotatedArray.js index 73eeddc..8cee4e5 100644 --- a/rotatedArray/rotatedArray.js +++ b/rotatedArray/rotatedArray.js @@ -39,24 +39,34 @@ const rotatedArraySearch = (arr, queryNum) => { console.log(`TOTAL number of array elements: ${len}`); if (!(queryNum >= low && high >= queryNum)) { console.log(null); + console.log('\n'); } else { if ((len - queryNum) <= lowIndex) { - console.log(arr[lowIndex - (len - queryNum)]); + console.log(`${arr[lowIndex - (len - queryNum)]}\n`); return arr[lowIndex - (len - queryNum)]; } else { - console.log(arr[len - queryNum]); + console.log(`${arr[lowIndex + queryNum]}\n`); return arr[len - queryNum]; }; }; }; -// TEST SUITE -rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], -1); -rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 0); -rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 1); -rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 2); -rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 3); -rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 4); -rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 5); -rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 6); -rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 7); +// // TEST SUITE +// rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], -1); +// rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 0); +// rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 1); +// rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 2); +// rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 3); +// rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 4); +// rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 5); +// rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 6); +// rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 7); + +rotatedArraySearch([4, 5, 6, 7, 2, 3], 1); +rotatedArraySearch([4, 5, 6, 7, 2, 3], 2); +rotatedArraySearch([4, 5, 6, 7, 2, 3], 3); +rotatedArraySearch([4, 5, 6, 7, 2, 3], 4); +rotatedArraySearch([4, 5, 6, 7, 2, 3], 5); +rotatedArraySearch([4, 5, 6, 7, 2, 3], 6); +rotatedArraySearch([4, 5, 6, 7, 2, 3], 7); +rotatedArraySearch([4, 5, 6, 7, 2, 3], 8); From 182869ddf8498116b07e9fa9f56c5530112665df Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 11 Aug 2017 12:23:33 -0400 Subject: [PATCH 244/523] cc25 linkedListCycles --- linkedListCycle/linkedListCycle.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linkedListCycle/linkedListCycle.js b/linkedListCycle/linkedListCycle.js index 03864f1..a58d559 100644 --- a/linkedListCycle/linkedListCycle.js +++ b/linkedListCycle/linkedListCycle.js @@ -1,4 +1,4 @@ -/* +/* cc25 linkedListCycles * Create a function that returns true if a linked list contains a cycle, or false if it terminates * * Usually we assume that a linked list will end with a null next pointer, for example: @@ -28,4 +28,4 @@ * Constraint 2: Do this in constant space * Constraint 3: Do not mutate the original nodes in any way * Hint: Search for Floyd's Tortoise and Hare algorithm. - */ \ No newline at end of file + */ From 5ac4c9c6c3e2fa6d6fd2722e4b36d2fc692c2d3f Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 11 Aug 2017 12:56:36 -0400 Subject: [PATCH 245/523] cc24 rotatedArray solution --- rotatedArray/solution.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 rotatedArray/solution.js diff --git a/rotatedArray/solution.js b/rotatedArray/solution.js new file mode 100644 index 0000000..e69de29 From f50060bdaf4763c45a2d036b2548a1ba4d4ff207 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Fri, 11 Aug 2017 13:45:55 -0400 Subject: [PATCH 246/523] idem --- rotatedArray/solution.js | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/rotatedArray/solution.js b/rotatedArray/solution.js index e69de29..c99cae6 100644 --- a/rotatedArray/solution.js +++ b/rotatedArray/solution.js @@ -0,0 +1,55 @@ +/* + * Given a sorted array that has been rotated some number of items right or + * left, i.e. [0, 1, 2, 3, 4, 5, 6, 7] might become [4, 5, 6, 7, 0, 1, 2, 3] + * how can you efficiently find an element? For simplicity, you can assume + * that there are no duplicate elements in the array. + * + * rotatedArraySearch should return the index of the element if it is in the + * array and should return null otherwise. + * + * For instance: + * rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 2) === 5 + * + * rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 100) === null + * + * Target time complexity: O(log(n)) + */ + +const rotatedArraySearch = (arr, number) => { + // low = 0 + // high = arr.length - 1 + // while low <= high + // create middle to be initialized to avg of low + high + // check if arr[middle] === number, if so, return middle + // if array[low] <= array[middle] + // if array[low] <= number && number < array[middle] + // set high to middle - 1 + // else low = middle + 1 + // else + // if arr[middle] < number && number <= array[high] + // low = mid + 1; + // else high = middle - 1 + // return null; + let low = 0; + let high = arr.length - 1; + while (low <= high) { + const mid = Math.floor((low + high) / 2); + if (arr[mid] === number) return mid; + if (arr[low] <= arr[mid]) { + if (arr[low] <= number && number < arr[mid]) { + high = mid - 1; + } else { + low = mid + 1; + } + } else { + if (arr[mid] < number && number <= arr[high]) { + low = mid + 1; + } else { + high = mid - 1; + } + } + } + return null; +}; + +console.log(rotatedArraySearch([4, 5, 6, 0, 1, 2, 3], 2)); // === 5; From ce16092e7bc3076bd50cd0da710a0c35982b1a0f Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 14 Aug 2017 12:03:34 -0400 Subject: [PATCH 247/523] cc26 blueSquare --- blueSquares/index.html | 11 +++++++++++ blueSquares/script.js | 0 blueSquares/styles.css | 0 3 files changed, 11 insertions(+) create mode 100644 blueSquares/index.html create mode 100644 blueSquares/script.js create mode 100644 blueSquares/styles.css diff --git a/blueSquares/index.html b/blueSquares/index.html new file mode 100644 index 0000000..304255e --- /dev/null +++ b/blueSquares/index.html @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/blueSquares/script.js b/blueSquares/script.js new file mode 100644 index 0000000..e69de29 diff --git a/blueSquares/styles.css b/blueSquares/styles.css new file mode 100644 index 0000000..e69de29 From 7c8fd6b58aae3dda44ef89e99b21e15320498ebf Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 14 Aug 2017 12:20:53 -0400 Subject: [PATCH 248/523] cc26 blueSquares: 8 flex boxes --- blueSquares/index.html | 28 ++++++++++++++++++++++++---- blueSquares/styles.css | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/blueSquares/index.html b/blueSquares/index.html index 304255e..e20f755 100644 --- a/blueSquares/index.html +++ b/blueSquares/index.html @@ -1,11 +1,31 @@ - + + - - + + cc26 Blue Squares + + + + - +

HELLO WORLD

+ +
+
    +
  • 1
  • +
  • 2
  • +
  • 3
  • +
  • 4
  • +
  • 5
  • +
  • 6
  • +
  • 7
  • +
  • 8
  • +
+
+ + diff --git a/blueSquares/styles.css b/blueSquares/styles.css index e69de29..ef4f83c 100644 --- a/blueSquares/styles.css +++ b/blueSquares/styles.css @@ -0,0 +1,34 @@ +@import "compass/css3"; + +body { + background: black; +} + +.flex-container { + padding: 0; + margin: 0; + list-style: none; + + display: -webkit-box; + display: -moz-box; + display: -ms-flexbox; + display: -webkit-flex; + display: flex; + + -webkit-flex-flow: row wrap; + justify-content: space-around; +} + +.flex-item { + background: tomato; + padding: 5px; + width: 200px; + height: 150px; + margin-top: 10px; + + line-height: 150px; + color: white; + font-weight: bold; + font-size: 3em; + text-align: center; +} From 3014198832306136ae0f6d49501142e946a87770 Mon Sep 17 00:00:00 2001 From: mixelpixel Date: Mon, 14 Aug 2017 12:58:51 -0400 Subject: [PATCH 249/523] flex box, no jquery yet --- blueSquares/index.html | 2 +- blueSquares/script.js | 5 +++++ blueSquares/styles.css | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/blueSquares/index.html b/blueSquares/index.html index e20f755..f6c33d2 100644 --- a/blueSquares/index.html +++ b/blueSquares/index.html @@ -13,7 +13,7 @@

HELLO WORLD

-
+