From a762ea367c86ab4c14fa1cdeba518c609e3b54d7 Mon Sep 17 00:00:00 2001 From: phytertek Date: Tue, 8 Aug 2017 12:33:53 -0400 Subject: [PATCH 01/34] longestString challenge complete --- longestString/longestString.js | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/longestString/longestString.js b/longestString/longestString.js index 35b887c..37725d5 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -2,3 +2,41 @@ * Write a function that accepts an array of strings. * Return the longest string in the array. */ + +// Test Cases +/** + * ['Loooong', 'short', 'abcde'] => 'Loooong' + * ['AAAAAA','BBBB', 'CCCCC', 'DDDDDD'] => 'AAAAAA' + * [] => '' + */ + +// Psuedo Code +/** +* function longestString ([strings]) +* variable longestStringSoFar equals blank +* iterate over array of strings +* if current string is longer than longestStringSoFar +* set longestStringSoFar as current string +* return longestStringSoFar +*/ + +// Solution + +const longestString = (strings) => { + let longestStringSoFar = ''; + strings.forEach(string => { + if (string.length > longestStringSoFar.length) { + longestStringSoFar = string; + } + }); + return longestStringSoFar; +} + +// Tests +const test1 = ['Loooong', 'short', 'abcde']; +const test2 = ['AAAAAA','BBBB', 'CCCCC', 'DDDDDD'] +const test3 = [] + +console.log(longestString(test1) === 'Loooong') +console.log(longestString(test2) === 'AAAAAA') +console.log(longestString(test3) === '') From fca37ca72a8e4b11c21e7fb2bdd2002bf8d25108 Mon Sep 17 00:00:00 2001 From: phytertek Date: Tue, 8 Aug 2017 13:51:02 -0400 Subject: [PATCH 02/34] updated for null edge case --- longestString/longestString.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/longestString/longestString.js b/longestString/longestString.js index 37725d5..6485fae 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -7,13 +7,15 @@ /** * ['Loooong', 'short', 'abcde'] => 'Loooong' * ['AAAAAA','BBBB', 'CCCCC', 'DDDDDD'] => 'AAAAAA' - * [] => '' + * [] => null */ // Psuedo Code /** * function longestString ([strings]) -* variable longestStringSoFar equals blank +* variable longestStringSoFar equals the first element of the string array +* if longestStringSoFar equals null +* return null * iterate over array of strings * if current string is longer than longestStringSoFar * set longestStringSoFar as current string @@ -23,7 +25,8 @@ // Solution const longestString = (strings) => { - let longestStringSoFar = ''; + let longestStringSoFar = strings[0]; + if (!longestStringSoFar) return null strings.forEach(string => { if (string.length > longestStringSoFar.length) { longestStringSoFar = string; @@ -39,4 +42,4 @@ const test3 = [] console.log(longestString(test1) === 'Loooong') console.log(longestString(test2) === 'AAAAAA') -console.log(longestString(test3) === '') +console.log(longestString(test3) === null) From d86f3a7ad944497c2b0d4db15b89f570220df7a3 Mon Sep 17 00:00:00 2001 From: phytertek Date: Wed, 9 Aug 2017 12:14:00 -0400 Subject: [PATCH 03/34] Reverse Case Complete --- longestString/longestString.js | 6 +++--- reverseCase/reverseCase.js | 35 +++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/longestString/longestString.js b/longestString/longestString.js index 6485fae..cdb5503 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -13,9 +13,9 @@ // Psuedo Code /** * function longestString ([strings]) -* variable longestStringSoFar equals the first element of the string array -* if longestStringSoFar equals null +* if strings array is empty * return null +* variable longestStringSoFar equals the first element of the string array * iterate over array of strings * if current string is longer than longestStringSoFar * set longestStringSoFar as current string @@ -25,8 +25,8 @@ // Solution const longestString = (strings) => { + if (strings.length === null) return null let longestStringSoFar = strings[0]; - if (!longestStringSoFar) return null strings.forEach(string => { if (string.length > longestStringSoFar.length) { longestStringSoFar = string; diff --git a/reverseCase/reverseCase.js b/reverseCase/reverseCase.js index f1051f5..0960503 100644 --- a/reverseCase/reverseCase.js +++ b/reverseCase/reverseCase.js @@ -2,4 +2,37 @@ * 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. - */ \ No newline at end of file + */ + + // Test Cases +/** + * "Hello World" => "hELLO wORLD" + * "i AM a STRING" => "I am A string" + */ + + // Psuedo Code + /** + * split string into an array + * map over string array + * if current char is uppercase + * return char as lowercase + * if current char is lowercase + * return char as uppercase + * join array as string and return + */ + + // Solution + const reversCase = (string) => string + .split('') + .map(char => { + if (char === char.toUpperCase()) return char.toLowerCase(); + else return char.toUpperCase(); + }) + .join(''); + + // Tests + const test1 = "Hello World"; + const test2 = "i AM a STRING"; + + console.log(reversCase(test1) === 'hELLO wORLD'); + console.log(reversCase(test2) === 'I am A string'); From 0057614f7392953d03753bd0b9cb3f11d6292b1b Mon Sep 17 00:00:00 2001 From: phytertek Date: Wed, 9 Aug 2017 12:27:05 -0400 Subject: [PATCH 04/34] fixed accidental change to longestString --- longestString/longestString.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longestString/longestString.js b/longestString/longestString.js index cdb5503..99ff108 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -25,8 +25,8 @@ // Solution const longestString = (strings) => { - if (strings.length === null) return null let longestStringSoFar = strings[0]; + if (!longestStringSoFar) return null strings.forEach(string => { if (string.length > longestStringSoFar.length) { longestStringSoFar = string; From 38bbef1d0f7e6180f9158316546e5e2bdf6c261b Mon Sep 17 00:00:00 2001 From: phytertek Date: Wed, 9 Aug 2017 12:33:50 -0400 Subject: [PATCH 05/34] Reverse String refactor if/else to ternary --- reverseCase/reverseCase.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/reverseCase/reverseCase.js b/reverseCase/reverseCase.js index 0960503..86b8775 100644 --- a/reverseCase/reverseCase.js +++ b/reverseCase/reverseCase.js @@ -24,11 +24,9 @@ // Solution const reversCase = (string) => string .split('') - .map(char => { - if (char === char.toUpperCase()) return char.toLowerCase(); - else return char.toUpperCase(); - }) - .join(''); + .map(c => c.toUpperCase() === c ? c.toLowerCase() : c.toUpperCase()) + .join('') + // Tests const test1 = "Hello World"; From 664d9571e67eb9d027e337e3beb5cddc363f3453 Mon Sep 17 00:00:00 2001 From: phytertek Date: Thu, 10 Aug 2017 12:28:02 -0400 Subject: [PATCH 06/34] isUnique challenge complete --- isUnique/isUnique.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/isUnique/isUnique.js b/isUnique/isUnique.js index 6c9caf5..206d4cf 100644 --- a/isUnique/isUnique.js +++ b/isUnique/isUnique.js @@ -1,3 +1,41 @@ /* Implement an algorithm to determine if a string has all unique characters. * What if you cannot use additional data structures? - */ \ No newline at end of file + */ + +// Test Cases +/** + * 'AAABBBCCC' => false + * 'ABCDEFGHI' => true + * 'AaBbCcDdEe' => true + * 'ABCabcABCabc' => false + * '' => true + */ + +// Psuedo Code +/** +* split the string into an array +* filter the array +* return only if the current character's in the string array +* matches the current iteration's index +* compare the length of the filtered array to the length of the string +* if the lengths match return true, else false +*/ + +//Solution +const isUnique = (string) => string + .split('') + .filter((val, index, self) => self.indexOf(val) === index) + .length === string.length; + +//Tests +const test1 = 'AAABBBCCC' // => false +const test2 = 'ABCDEFGHI' // => true +const test3 = 'AaBbCcDdEe' // => false +const test4 = 'ABCabcABCabc' // => false +const test5 = '' // => true + +console.log(isUnique(test1)) +console.log(isUnique(test2)) +console.log(isUnique(test3)) +console.log(isUnique(test4)) +console.log(isUnique(test5)) From c1cdfe7a37acfe936018d6bd3c4490019521f8e2 Mon Sep 17 00:00:00 2001 From: phytertek Date: Thu, 10 Aug 2017 18:45:09 -0400 Subject: [PATCH 07/34] refactor to use Set --- isUnique/isUnique.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/isUnique/isUnique.js b/isUnique/isUnique.js index 206d4cf..a1d3433 100644 --- a/isUnique/isUnique.js +++ b/isUnique/isUnique.js @@ -13,24 +13,17 @@ // Psuedo Code /** -* split the string into an array -* filter the array -* return only if the current character's in the string array -* matches the current iteration's index -* compare the length of the filtered array to the length of the string -* if the lengths match return true, else false +* create a new Set with the string char values (which automatically dedupes string chars) +* return set size compared to string length */ //Solution -const isUnique = (string) => string - .split('') - .filter((val, index, self) => self.indexOf(val) === index) - .length === string.length; +const isUnique = (string) => new Set(string).size === string.length //Tests const test1 = 'AAABBBCCC' // => false const test2 = 'ABCDEFGHI' // => true -const test3 = 'AaBbCcDdEe' // => false +const test3 = 'AaBbCcDdEe' // => true const test4 = 'ABCabcABCabc' // => false const test5 = '' // => true From 09e7e2f2c651daa52622c9f1f2a4218835626b01 Mon Sep 17 00:00:00 2001 From: phytertek Date: Fri, 11 Aug 2017 12:22:13 -0400 Subject: [PATCH 08/34] callBackPractice complete --- callBackPractice/callBackPractice.js | 18 +- .../hyper-atom-dark-transparent/README.md | 24 +++ .../hyper-atom-dark-transparent/close.svg | 3 + .../hyper-atom-dark-transparent/index.js | 159 ++++++++++++++++++ .../hyper-atom-dark-transparent/package.json | 51 ++++++ package-lock.json | 11 ++ 6 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 node_modules/hyper-atom-dark-transparent/README.md create mode 100755 node_modules/hyper-atom-dark-transparent/close.svg create mode 100644 node_modules/hyper-atom-dark-transparent/index.js create mode 100644 node_modules/hyper-atom-dark-transparent/package.json create mode 100644 package-lock.json diff --git a/callBackPractice/callBackPractice.js b/callBackPractice/callBackPractice.js index 8f5d9ac..a90f101 100644 --- a/callBackPractice/callBackPractice.js +++ b/callBackPractice/callBackPractice.js @@ -24,18 +24,24 @@ firstItem(foods, (firstItem) => { console.log(`The first item is ${firstItem}.`); }); +const firstItem = (arr, cb) => cb(arr[0]); + // Write a function called getLength that passes the length of the array into the callback getLength(foods, (length) => { console.log(`The length of the array is ${length}.`); }); +const getLength = (arr, cb) => cb(arr.length); + // Write a function called last which passes the last item of the array into the callback last(foods, (lastItem) => { console.log(`The last item in the array is ${lastItem}.`); }); +const last = (arr, cb) => cb(arr[arr.length - 1]); + // Write a function called sumNums that adds two numbers and passes the result to the callback @@ -43,12 +49,16 @@ sumNums(5, 10, (sum) => { console.log(`The sum is ${sum}.`); }); +const sumNums = (a, b, cb) => cb(a + b); + // Write a function called multiplyNums that adds two numbers and passes the result to the callback multiplyNums(5, 10, (product) => { console.log(`The product is ${product}.`); }); +const multiplyNums = (a, b, cb) => cb(a * b); + // 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 @@ -56,6 +66,8 @@ contains(foods, 'ribeye', (result) => { console.log(result ? 'ribeye is in the array' : 'ribeye is not in the array'); }); +const contains = (arr, item, cb) => cb(foods.indexOf(item) !== -1) + // 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. @@ -63,9 +75,13 @@ removeDuplicates(foods, (uniqueFoods) => { console.log(`foods with duplicates removed: ${uniqueFoods}`); }); +const removeDuplicates = (arr, cb) => cb(new Set(arr)) + // Write a function called forEach that iterates over the provided array and passes the value and index into the callback. forEach(foods, (value, index) => { console.log(`${value} is at index ${index}.`); -}); \ No newline at end of file +}); + +const forEach = (arr, cb) => arr.forEach((v, i) => cb(v, i)); // <- Instructions never said not to use array builtin methods ;) \ No newline at end of file diff --git a/node_modules/hyper-atom-dark-transparent/README.md b/node_modules/hyper-atom-dark-transparent/README.md new file mode 100644 index 0000000..7322643 --- /dev/null +++ b/node_modules/hyper-atom-dark-transparent/README.md @@ -0,0 +1,24 @@ +# Atom One Dark for Hyper + +[Hyper](https://hyper.is) theme based on [the Atom One Dark theme](https://github.com/atom/one-dark-syntax). Forked from @mdo's [hyperterm-atom-dark](https://github.com/mdo/hyperterm-atom-dark) and modified by @simonmeusel. + +![Screenshot with Background](http://i.imgur.com/Y8ihe51.png) + +Color scheme: +![Screenshot with tabs](https://cloud.githubusercontent.com/assets/98681/16899206/f644c080-4baf-11e6-890d-fd5c628c7991.png) + +### Install + +1. Open HyperTerm's preferences with `Cmd+,` (or manually at `~/.hyper.js`) with your editor. +2. Update your list of plugins to include `hyper-atom-dark-transparent`, like so: + + ```js +plugins: [ + 'hyper-atom-dark-transparent' +], +``` +3. Fully reload HyperTerm (`Cmd+Shift+R`), and tada! + +### License + +MIT diff --git a/node_modules/hyper-atom-dark-transparent/close.svg b/node_modules/hyper-atom-dark-transparent/close.svg new file mode 100755 index 0000000..11ff5bd --- /dev/null +++ b/node_modules/hyper-atom-dark-transparent/close.svg @@ -0,0 +1,3 @@ + + + diff --git a/node_modules/hyper-atom-dark-transparent/index.js b/node_modules/hyper-atom-dark-transparent/index.js new file mode 100644 index 0000000..83354ec --- /dev/null +++ b/node_modules/hyper-atom-dark-transparent/index.js @@ -0,0 +1,159 @@ + +const backgroundColor = 'rgba(40, 44, 52, 0.99)' +const foregroundColor = '#abb2bf' +const cursorColor = foregroundColor +const borderColor = backgroundColor + +const colors = { + black : backgroundColor, + red : '#e06c75', // red + green : '#98c379', // green + yellow : '#d19a66', // yellow + blue : '#56b6c2', // blue + magenta : '#c678dd', // pink + cyan : '#56b6c2', // cyan + white : '#d0d0d0', // light gray + lightBlack : '#808080', // medium gray + lightRed : '#e06c75', // red + lightGreen : '#98c379', // green + lightYellow : '#d19a66', // yellow + lightBlue : '#56b6c2', // blue + lightMagenta: '#c678dd', // pink + lightCyan : '#56b6c2', // cyan + colorCubes : '#ffffff', // white + grayscale : foregroundColor +} + +exports.decorateConfig = config => { + return Object.assign({}, config, { + foregroundColor, + backgroundColor, + borderColor, + cursorColor, + colors, + termCSS: ` + ${config.termCSS || ''} + .cursor-node { + mix-blend-mode: difference; + border-left-width: 2px; + } + `, + css: ` + ${config.css || ''} + .header_header { + top: 0; + right: 0; + left: 0; + } + .tabs_list { + background-color: #21252b !important; + border-bottom-color: #181a1f !important; + } + .tab_tab { + font-weight: 500; + color: rgba(157, 165, 180, 0.6); + border-width: 0 0 0 1px; + border-image: linear-gradient(#21252b, #181a1f 1em) 0 0 0 1 stretch; + border-style: solid; + } + .tab_tab:first-of-type { + border-width: 0; + } + .tab_tab:hover { + color: rgba(157, 165, 180, 0.6); + transition: none; + } + .tab_tab::after { + content: ""; + position: absolute; + pointer-events: none; + top: 0; + bottom: -1px; + left: 0; + width: 2px; + height: inherit; + background: #528bff; + opacity: 0; + transition: opacity .16s; + z-index: 1; + } + .tabs_title, + .tab_tab.tab_active { + font-weight: 500; + color: #d7dae0; + } + .tab_tab.tab_active { + background-color: ${backgroundColor}; + } + .tab_tab.tab_active, + .tab_tab.tab_active + .tab_tab { + border-image: linear-gradient(transparent, transparent) 0 0 0 1 stretch; + } + .tab_tab.tab_active::before { + content: ""; + z-index: 1; + position: absolute; + top: 0; + left: -1px; + bottom: -1px; + right: 0; + height: inherit; + background-image: linear-gradient(rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0)); + box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.06); + border: 1px solid #181a1f; + border-bottom-color: ${backgroundColor}; + border-top: 0; + } + .tab_tab.tab_active:last-of-type::before { + border-right-width: 0; + } + .tab_tab.tab_active::after { + opacity: 1; + transition-duration: .32s; + } + .tab_icon { + display: block; + background: rgba(157, 165, 180, 0.6); + -webkit-mask-image: url('${__dirname}/close.svg'); + mask-image: url('${__dirname}/close.svg'); + -webkit-mask-size: 7px; + mask-size: 7px; + -webkit-mask-repeat: no-repeat; + mask-repeat: no-repeat; + -webkit-mask-position-y: center; + mask-position-y: center; + -webkit-mask-position-x: 8px; + mask-position-x: 8px; + width: 26px; + height: 100%; + top: 0; + right: 0; + transform: scale(0); + transition: transform .08s; + opacity: 1; + border-radius: 0; + z-index: 2; + } + .tab_icon:hover { + background: rgba(157, 165, 180, 0.6); + opacity: .7; + } + .tab_tab.tab_active .tab_icon { + background: #d7dae0; + } + .tab_tab.tab_active .tab_icon:hover { + background: #d7dae0; + } + .tab_tab:hover .tab_icon { + transform: scale(1); + transition-duration: .16s; + } + .tab_icon svg { + display: none; + } + .tab_icon::after { + display: none; + } + ` + }) +} diff --git a/node_modules/hyper-atom-dark-transparent/package.json b/node_modules/hyper-atom-dark-transparent/package.json new file mode 100644 index 0000000..7e2e842 --- /dev/null +++ b/node_modules/hyper-atom-dark-transparent/package.json @@ -0,0 +1,51 @@ +{ + "_from": "hyper-atom-dark-transparent", + "_id": "hyper-atom-dark-transparent@1.1.4", + "_inBundle": false, + "_integrity": "sha1-KRR1XylndKP4lV1HNOyROjDrzUo=", + "_location": "/hyper-atom-dark-transparent", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "hyper-atom-dark-transparent", + "name": "hyper-atom-dark-transparent", + "escapedName": "hyper-atom-dark-transparent", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/hyper-atom-dark-transparent/-/hyper-atom-dark-transparent-1.1.4.tgz", + "_shasum": "2914755f296774a3f8955d4734ec913a30ebcd4a", + "_spec": "hyper-atom-dark-transparent", + "_where": "/home/phytertek/LS/CS2-Code-Challenges", + "author": { + "name": "Simon Meusel" + }, + "bugs": { + "url": "https://github.com/simonmeusel/hyperterm-atom-dark/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "Hyper theme based on the hyperterm-atom-dark, but with transparency.", + "homepage": "https://github.com/simonmeusel/hyperterm-atom-dark#readme", + "keywords": [ + "hyper", + "hyper-theme", + "colors", + "transparent", + "atom" + ], + "license": "MIT", + "main": "index.js", + "name": "hyper-atom-dark-transparent", + "repository": { + "type": "git", + "url": "git+https://github.com/simonmeusel/hyperterm-atom-dark.git" + }, + "version": "1.1.4" +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..dcbd41a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,11 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "hyper-atom-dark-transparent": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/hyper-atom-dark-transparent/-/hyper-atom-dark-transparent-1.1.4.tgz", + "integrity": "sha1-KRR1XylndKP4lV1HNOyROjDrzUo=" + } + } +} From 5ea9d06fbe963a495fed770eedf0df2c30f8d385 Mon Sep 17 00:00:00 2001 From: phytertek Date: Fri, 11 Aug 2017 12:27:47 -0400 Subject: [PATCH 09/34] fix ordering of functions in callBackPractice --- callBackPractice/callBackPractice.js | 32 +++++++++++++--------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/callBackPractice/callBackPractice.js b/callBackPractice/callBackPractice.js index a90f101..d1daaa9 100644 --- a/callBackPractice/callBackPractice.js +++ b/callBackPractice/callBackPractice.js @@ -20,68 +20,66 @@ 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}.`); }); -const firstItem = (arr, cb) => cb(arr[0]); - // 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}.`); }); -const getLength = (arr, cb) => cb(arr.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}.`); }); -const last = (arr, cb) => cb(arr[arr.length - 1]); - // Write a function called sumNums that adds two numbers and passes the result to the callback +const sumNums = (a, b, cb) => cb(a + b); sumNums(5, 10, (sum) => { console.log(`The sum is ${sum}.`); }); -const sumNums = (a, b, cb) => cb(a + b); - // Write a function called multiplyNums that adds two numbers and passes the result to the callback +const multiplyNums = (a, b, cb) => cb(a * b); + multiplyNums(5, 10, (product) => { console.log(`The product is ${product}.`); }); -const multiplyNums = (a, b, cb) => cb(a * b); - // 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, item, cb) => cb(foods.indexOf(item) !== -1) + contains(foods, 'ribeye', (result) => { console.log(result ? 'ribeye is in the array' : 'ribeye is not in the array'); }); -const contains = (arr, item, cb) => cb(foods.indexOf(item) !== -1) - // 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) => cb(Array.from(new Set(arr))) + removeDuplicates(foods, (uniqueFoods) => { console.log(`foods with duplicates removed: ${uniqueFoods}`); }); -const removeDuplicates = (arr, cb) => cb(new Set(arr)) - // Write a function called forEach that iterates over the provided array and passes the value and index into the callback. +const forEach = (arr, cb) => arr.forEach((v, i) => cb(v, i)); // <- Instructions never said not to use array builtin methods ;) forEach(foods, (value, index) => { console.log(`${value} is at index ${index}.`); -}); - -const forEach = (arr, cb) => arr.forEach((v, i) => cb(v, i)); // <- Instructions never said not to use array builtin methods ;) \ No newline at end of file +}); \ No newline at end of file From 1ad668243c646e90efe693b991279a25171cf2a7 Mon Sep 17 00:00:00 2001 From: phytertek Date: Fri, 11 Aug 2017 12:42:08 -0400 Subject: [PATCH 10/34] fix typo in contains function on callBackPractice --- callBackPractice/callBackPractice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/callBackPractice/callBackPractice.js b/callBackPractice/callBackPractice.js index d1daaa9..e41be4f 100644 --- a/callBackPractice/callBackPractice.js +++ b/callBackPractice/callBackPractice.js @@ -61,7 +61,7 @@ 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 -const contains = (arr, item, cb) => cb(foods.indexOf(item) !== -1) +const contains = (arr, item, cb) => cb(arr.indexOf(item) !== -1) contains(foods, 'ribeye', (result) => { console.log(result ? 'ribeye is in the array' : 'ribeye is not in the array'); From aef4b5bf4d7be482e465a3909e4889b8d64b2bf1 Mon Sep 17 00:00:00 2001 From: phytertek Date: Fri, 11 Aug 2017 19:05:22 -0400 Subject: [PATCH 11/34] fix --- .../hyper-atom-dark-transparent/README.md | 24 --- .../hyper-atom-dark-transparent/close.svg | 3 - .../hyper-atom-dark-transparent/index.js | 159 ------------------ .../hyper-atom-dark-transparent/package.json | 51 ------ 4 files changed, 237 deletions(-) delete mode 100644 node_modules/hyper-atom-dark-transparent/README.md delete mode 100755 node_modules/hyper-atom-dark-transparent/close.svg delete mode 100644 node_modules/hyper-atom-dark-transparent/index.js delete mode 100644 node_modules/hyper-atom-dark-transparent/package.json diff --git a/node_modules/hyper-atom-dark-transparent/README.md b/node_modules/hyper-atom-dark-transparent/README.md deleted file mode 100644 index 7322643..0000000 --- a/node_modules/hyper-atom-dark-transparent/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Atom One Dark for Hyper - -[Hyper](https://hyper.is) theme based on [the Atom One Dark theme](https://github.com/atom/one-dark-syntax). Forked from @mdo's [hyperterm-atom-dark](https://github.com/mdo/hyperterm-atom-dark) and modified by @simonmeusel. - -![Screenshot with Background](http://i.imgur.com/Y8ihe51.png) - -Color scheme: -![Screenshot with tabs](https://cloud.githubusercontent.com/assets/98681/16899206/f644c080-4baf-11e6-890d-fd5c628c7991.png) - -### Install - -1. Open HyperTerm's preferences with `Cmd+,` (or manually at `~/.hyper.js`) with your editor. -2. Update your list of plugins to include `hyper-atom-dark-transparent`, like so: - - ```js -plugins: [ - 'hyper-atom-dark-transparent' -], -``` -3. Fully reload HyperTerm (`Cmd+Shift+R`), and tada! - -### License - -MIT diff --git a/node_modules/hyper-atom-dark-transparent/close.svg b/node_modules/hyper-atom-dark-transparent/close.svg deleted file mode 100755 index 11ff5bd..0000000 --- a/node_modules/hyper-atom-dark-transparent/close.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/node_modules/hyper-atom-dark-transparent/index.js b/node_modules/hyper-atom-dark-transparent/index.js deleted file mode 100644 index 83354ec..0000000 --- a/node_modules/hyper-atom-dark-transparent/index.js +++ /dev/null @@ -1,159 +0,0 @@ - -const backgroundColor = 'rgba(40, 44, 52, 0.99)' -const foregroundColor = '#abb2bf' -const cursorColor = foregroundColor -const borderColor = backgroundColor - -const colors = { - black : backgroundColor, - red : '#e06c75', // red - green : '#98c379', // green - yellow : '#d19a66', // yellow - blue : '#56b6c2', // blue - magenta : '#c678dd', // pink - cyan : '#56b6c2', // cyan - white : '#d0d0d0', // light gray - lightBlack : '#808080', // medium gray - lightRed : '#e06c75', // red - lightGreen : '#98c379', // green - lightYellow : '#d19a66', // yellow - lightBlue : '#56b6c2', // blue - lightMagenta: '#c678dd', // pink - lightCyan : '#56b6c2', // cyan - colorCubes : '#ffffff', // white - grayscale : foregroundColor -} - -exports.decorateConfig = config => { - return Object.assign({}, config, { - foregroundColor, - backgroundColor, - borderColor, - cursorColor, - colors, - termCSS: ` - ${config.termCSS || ''} - .cursor-node { - mix-blend-mode: difference; - border-left-width: 2px; - } - `, - css: ` - ${config.css || ''} - .header_header { - top: 0; - right: 0; - left: 0; - } - .tabs_list { - background-color: #21252b !important; - border-bottom-color: #181a1f !important; - } - .tab_tab { - font-weight: 500; - color: rgba(157, 165, 180, 0.6); - border-width: 0 0 0 1px; - border-image: linear-gradient(#21252b, #181a1f 1em) 0 0 0 1 stretch; - border-style: solid; - } - .tab_tab:first-of-type { - border-width: 0; - } - .tab_tab:hover { - color: rgba(157, 165, 180, 0.6); - transition: none; - } - .tab_tab::after { - content: ""; - position: absolute; - pointer-events: none; - top: 0; - bottom: -1px; - left: 0; - width: 2px; - height: inherit; - background: #528bff; - opacity: 0; - transition: opacity .16s; - z-index: 1; - } - .tabs_title, - .tab_tab.tab_active { - font-weight: 500; - color: #d7dae0; - } - .tab_tab.tab_active { - background-color: ${backgroundColor}; - } - .tab_tab.tab_active, - .tab_tab.tab_active + .tab_tab { - border-image: linear-gradient(transparent, transparent) 0 0 0 1 stretch; - } - .tab_tab.tab_active::before { - content: ""; - z-index: 1; - position: absolute; - top: 0; - left: -1px; - bottom: -1px; - right: 0; - height: inherit; - background-image: linear-gradient(rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0)); - box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.06); - border: 1px solid #181a1f; - border-bottom-color: ${backgroundColor}; - border-top: 0; - } - .tab_tab.tab_active:last-of-type::before { - border-right-width: 0; - } - .tab_tab.tab_active::after { - opacity: 1; - transition-duration: .32s; - } - .tab_icon { - display: block; - background: rgba(157, 165, 180, 0.6); - -webkit-mask-image: url('${__dirname}/close.svg'); - mask-image: url('${__dirname}/close.svg'); - -webkit-mask-size: 7px; - mask-size: 7px; - -webkit-mask-repeat: no-repeat; - mask-repeat: no-repeat; - -webkit-mask-position-y: center; - mask-position-y: center; - -webkit-mask-position-x: 8px; - mask-position-x: 8px; - width: 26px; - height: 100%; - top: 0; - right: 0; - transform: scale(0); - transition: transform .08s; - opacity: 1; - border-radius: 0; - z-index: 2; - } - .tab_icon:hover { - background: rgba(157, 165, 180, 0.6); - opacity: .7; - } - .tab_tab.tab_active .tab_icon { - background: #d7dae0; - } - .tab_tab.tab_active .tab_icon:hover { - background: #d7dae0; - } - .tab_tab:hover .tab_icon { - transform: scale(1); - transition-duration: .16s; - } - .tab_icon svg { - display: none; - } - .tab_icon::after { - display: none; - } - ` - }) -} diff --git a/node_modules/hyper-atom-dark-transparent/package.json b/node_modules/hyper-atom-dark-transparent/package.json deleted file mode 100644 index 7e2e842..0000000 --- a/node_modules/hyper-atom-dark-transparent/package.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "_from": "hyper-atom-dark-transparent", - "_id": "hyper-atom-dark-transparent@1.1.4", - "_inBundle": false, - "_integrity": "sha1-KRR1XylndKP4lV1HNOyROjDrzUo=", - "_location": "/hyper-atom-dark-transparent", - "_phantomChildren": {}, - "_requested": { - "type": "tag", - "registry": true, - "raw": "hyper-atom-dark-transparent", - "name": "hyper-atom-dark-transparent", - "escapedName": "hyper-atom-dark-transparent", - "rawSpec": "", - "saveSpec": null, - "fetchSpec": "latest" - }, - "_requiredBy": [ - "#USER", - "/" - ], - "_resolved": "https://registry.npmjs.org/hyper-atom-dark-transparent/-/hyper-atom-dark-transparent-1.1.4.tgz", - "_shasum": "2914755f296774a3f8955d4734ec913a30ebcd4a", - "_spec": "hyper-atom-dark-transparent", - "_where": "/home/phytertek/LS/CS2-Code-Challenges", - "author": { - "name": "Simon Meusel" - }, - "bugs": { - "url": "https://github.com/simonmeusel/hyperterm-atom-dark/issues" - }, - "bundleDependencies": false, - "deprecated": false, - "description": "Hyper theme based on the hyperterm-atom-dark, but with transparency.", - "homepage": "https://github.com/simonmeusel/hyperterm-atom-dark#readme", - "keywords": [ - "hyper", - "hyper-theme", - "colors", - "transparent", - "atom" - ], - "license": "MIT", - "main": "index.js", - "name": "hyper-atom-dark-transparent", - "repository": { - "type": "git", - "url": "git+https://github.com/simonmeusel/hyperterm-atom-dark.git" - }, - "version": "1.1.4" -} From d41ec739e50fa3e8060fdd06e67906bdefe1002c Mon Sep 17 00:00:00 2001 From: phytertek Date: Mon, 14 Aug 2017 12:17:47 -0400 Subject: [PATCH 12/34] removeDuplicates complete --- removeDuplicates/removeDuplicates.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/removeDuplicates/removeDuplicates.js b/removeDuplicates/removeDuplicates.js index 970f719..46d2c09 100644 --- a/removeDuplicates/removeDuplicates.js +++ b/removeDuplicates/removeDuplicates.js @@ -8,6 +8,6 @@ * you're more than likely using a for loop under the hood. */ -const removeDuplicates = (arr) => { - //code here... -}; \ No newline at end of file +const removeDuplicates = (arr) => Array.from(new Set(arr)) + +const test1 = [1, 1, 1, 2, 2, 3, 4, 5, 5] // -> [1, 2, 3, 4, 5] \ No newline at end of file From 0804634a2433710db8ad0fac68afad56e4838512 Mon Sep 17 00:00:00 2001 From: phytertek Date: Tue, 15 Aug 2017 12:12:16 -0400 Subject: [PATCH 13/34] Water Jugs challenge complete --- brainTeasers/waterJugs.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/brainTeasers/waterJugs.md b/brainTeasers/waterJugs.md index 5276fc0..43cd5ab 100644 --- a/brainTeasers/waterJugs.md +++ b/brainTeasers/waterJugs.md @@ -1 +1,19 @@ 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. + +# fill the 3 quart jug + +# pour the 3 quarts into the 5 quart jug + +# flll the 3 quart jug + +# fill the remainder of the 5 quart jug, leaving 1 quart in the 3 quart jug + +# empty the 5 quart jug + +# pour the remaining 1 quart from the 3 quart jug into the 5 quart jug + +# fill the 3 quart jug + +# pour the 3 quarts into the 5 quart jug + +# the 5 quart jug now contains 4 quarts \ No newline at end of file From 7a0ff02833df7b033487406d69c8dfc0263c16d7 Mon Sep 17 00:00:00 2001 From: phytertek Date: Wed, 16 Aug 2017 12:17:08 -0400 Subject: [PATCH 14/34] forLoopTimeout challenge complete --- forLoopTimeout/forLoopTimeout.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/forLoopTimeout/forLoopTimeout.js b/forLoopTimeout/forLoopTimeout.js index 87522c2..64aad53 100644 --- a/forLoopTimeout/forLoopTimeout.js +++ b/forLoopTimeout/forLoopTimeout.js @@ -5,9 +5,19 @@ // I've been asked this three times in separate interviews. for (var 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); -} \ No newline at end of file + doSetTimeout(i) +} + +function doSetTimeout(i) { + setTimeout(function() { + console.log(i) + }, 0); +} + +// If you don't do something like this (and there are other variations on +// this same idea), then each of the timer handler functions will share the +// same variable "i". When the loop is finished, what's the value of "i"? +// It's 3! +// By using an intermediating function, a copy of the value of the +// variable is made. Since the timeout handler is created in the context of +// that copy, it has its own private "i" to use. \ No newline at end of file From 72c0471b778916e64c8799a63f760c4e6ada39a0 Mon Sep 17 00:00:00 2001 From: phytertek Date: Wed, 16 Aug 2017 12:19:18 -0400 Subject: [PATCH 15/34] typo --- forLoopTimeout/forLoopTimeout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forLoopTimeout/forLoopTimeout.js b/forLoopTimeout/forLoopTimeout.js index 64aad53..69f0966 100644 --- a/forLoopTimeout/forLoopTimeout.js +++ b/forLoopTimeout/forLoopTimeout.js @@ -17,7 +17,7 @@ function doSetTimeout(i) { // If you don't do something like this (and there are other variations on // this same idea), then each of the timer handler functions will share the // same variable "i". When the loop is finished, what's the value of "i"? -// It's 3! +// It's 11! // By using an intermediating function, a copy of the value of the // variable is made. Since the timeout handler is created in the context of // that copy, it has its own private "i" to use. \ No newline at end of file From 757ee91f24a23240307a054174970f89c99050f5 Mon Sep 17 00:00:00 2001 From: phytertek Date: Thu, 17 Aug 2017 12:14:36 -0400 Subject: [PATCH 16/34] largestPrimePalindrome challenge complete --- .../largestPrimePalindrome.js | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 4cc99c0..12ccff9 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -1,6 +1,31 @@ /* - * Create a function that returns the largest prime palindrome less than 1000. - * Hint: it's 929 - * You will first want to determine if the number is a palindrome and then determine if it is prime. - * A palindrome is a number that is the same forwards and backwards: 121, 323, 123454321, etc. - */ \ No newline at end of file +* Create a function that returns the largest prime palindrome less than 1000. +* Hint: it's 929 +* You will first want to determine if the number is a palindrome and then determine if it is prime. +* A palindrome is a number that is the same forwards and backwards: 121, 323, 123454321, etc. +*/ + +//Test 1000 => 929 + +const isPrime = (number) => { + if (number === 1 || number === 3) { + return false; + } + for (let i = 2; i < number; i++) { + if (number % i === 0) { + return false; + } + } + return true; +} + +const longestPalindromePrime = (number) => { + for (let i = 0; i < number; i++){ + const test = number - i; + if (isPrime(test) && test === parseInt([...test+''].reverse().join(''))) { + return test + } + } +} + +console.log(longestPalindromePrime(1000) === 929); \ No newline at end of file From 2ae39a41636c6e11dbc30cefb26db643bcbb5b52 Mon Sep 17 00:00:00 2001 From: phytertek Date: Thu, 17 Aug 2017 12:50:42 -0400 Subject: [PATCH 17/34] optimization1 of largestPrimePalindrome --- .../largestPrimePalindrome.js | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 12ccff9..f73b3ed 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -7,25 +7,23 @@ //Test 1000 => 929 -const isPrime = (number) => { - if (number === 1 || number === 3) { - return false; +function isPrime(number) { + if (number < 2) {return false} + if (number != Math.round(number)) {return false} + let isPrime = true; + for (var i = 2; i <= Math.sqrt(number); i++) { + if (number % i == 0) {isPrime = false} + } + return isPrime; } - for (let i = 2; i < number; i++) { - if (number % i === 0) { - return false; - } - } - return true; -} const longestPalindromePrime = (number) => { for (let i = 0; i < number; i++){ const test = number - i; - if (isPrime(test) && test === parseInt([...test+''].reverse().join(''))) { + if (isPrime(test) && test === parseInt([...test.toString()].reverse().join(''))) { return test } } } -console.log(longestPalindromePrime(1000) === 929); \ No newline at end of file +console.log(longestPalindromePrime(500)); \ No newline at end of file From aecf2ded1fe1c193465705342795c2b5b6be5852 Mon Sep 17 00:00:00 2001 From: phytertek Date: Thu, 17 Aug 2017 12:51:16 -0400 Subject: [PATCH 18/34] fix tabs --- largestPrimePalindrome/largestPrimePalindrome.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index f73b3ed..e39436d 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -8,14 +8,14 @@ //Test 1000 => 929 function isPrime(number) { - if (number < 2) {return false} - if (number != Math.round(number)) {return false} - let isPrime = true; - for (var i = 2; i <= Math.sqrt(number); i++) { - if (number % i == 0) {isPrime = false} - } - return isPrime; + if (number < 2) {return false} + if (number != Math.round(number)) {return false} + let isPrime = true; + for (var i = 2; i <= Math.sqrt(number); i++) { + if (number % i == 0) {isPrime = false} } + return isPrime; +} const longestPalindromePrime = (number) => { for (let i = 0; i < number; i++){ From 1e8a8a7a95675f924421a0c1c006ab36063d5a1e Mon Sep 17 00:00:00 2001 From: phytertek Date: Thu, 17 Aug 2017 12:54:34 -0400 Subject: [PATCH 19/34] var to let --- largestPrimePalindrome/largestPrimePalindrome.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index e39436d..02f63b1 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -11,7 +11,7 @@ function isPrime(number) { if (number < 2) {return false} if (number != Math.round(number)) {return false} let isPrime = true; - for (var i = 2; i <= Math.sqrt(number); i++) { + for (let i = 2; i <= Math.sqrt(number); i++) { if (number % i == 0) {isPrime = false} } return isPrime; From e7665f53f2f17b5ea88e6f2f8b4e65d1add4bc4e Mon Sep 17 00:00:00 2001 From: phytertek Date: Fri, 18 Aug 2017 12:06:55 -0400 Subject: [PATCH 20/34] Constructors challenge complete --- constructors/constructors.js | 148 +++++++++++++++++++++++++++++------ 1 file changed, 125 insertions(+), 23 deletions(-) diff --git a/constructors/constructors.js b/constructors/constructors.js index 54801f6..9499ebd 100644 --- a/constructors/constructors.js +++ b/constructors/constructors.js @@ -1,23 +1,125 @@ -/* Design several classes and their relationships for an RPG videogame. - * Classes: - * NPC -> Humanoid, Animal, Plant - * Humanoid -> Human, Elf, Orc - * Animal -> Bear, Wolf - * Plant -> FleshEatingDaisy - * - * Human -> Soldier, Peasant, Bandit - * - * NPC should be a general class for a non-player character in the game. - * This class will probably include general attributes like hp, strength, speed, etc. - * - * Humanoid, Animal, and Plant should all inherit from NPC. The classes - * shown to the right of the arrow are classes that will inherit - * from those classes. - * - * Soldier, Peasant, and Bandit should all inherit from Human. - * - * Create properties for these different classes that fit with the character. - * - * 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 + + +/* +* Design several classes and their relationships for an RPG videogame. +* Classes: +* NPC -> Humanoid, Animal, Plant +* Humanoid -> Human, Elf, Orc +* Animal -> Bear, Wolf +* Plant -> FleshEatingDaisy +* +* Human -> Soldier, Peasant, Bandit +* +* NPC should be a general class for a non-player character in the game. +* This class will probably include general attributes like hp, strength, speed, etc. +* +* Humanoid, Animal, and Plant should all inherit from NPC. The classes +* shown to the right of the arrow are classes that will inherit +* from those classes. +* +* Soldier, Peasant, and Bandit should all inherit from Human. +* +* Create properties for these different classes that fit with the character. +* +* This is how you would structure the game objects in an actual game +* application in Unity or another similar framework. +*/ + +class NPC { + constructor(attr) { + this.hp = attr.hp; + this.strength = attr.strength; + this.speed= attr.speed; + this.attack = attr.attack; + this.defend = attr.defend; + } +} + +class Humanoid extends NPC { + constructor(attr) { + super(attr) + // Humanoid Attributes + this.weapon = attr.weapon; + } +} + +class Animal extends NPC { + constructor(attr) { + super(attr) + // Animal Attributes + } +} + +class Plant extends NPC { + constructor(attr) { + super(attr) + // Plant Attributes + } +} + +class Human extends Humanoid { + constructor(attr) { + super(attr) + // Human Attributes + } +} + +class Elf extends Humanoid { + constructor(attr) { + super(attr) + // Elf Attributes + } +} + +class Orc extends Humanoid { + constructor(attr) { + super(attr) + // Orc Attributes + } +} + +class Bear extends Animal { + constructor(attr) { + super(attr) + // Bear Attributes + } +} + +class Wolf extends Animal { + constructor(attr) { + super(attr) + // Wolf Attributes + } +} + +class FleshEatingDaisy extends Plant { + constructor(attr) { + super(attr) + // FleshEatingDaisy Attributes + } +} + +class Soldier extends Humanoid { + constructor(attr) { + super(attr) + // Soldier Attributes + } +} + +class Peasant extends Humanoid { + constructor(attr) { + super(attr) + // Peasant Attributes + } +} + +class Bandit extends Humanoid { + constructor(attr) { + super(attr) + // Bandit Attributes + } +} + +const sl = new Soldier({hp: 100}) + +console.log(sl) \ No newline at end of file From bdfc74867d69b8308ddc3174ccb6105f07f2b425 Mon Sep 17 00:00:00 2001 From: phytertek Date: Fri, 18 Aug 2017 13:48:34 -0400 Subject: [PATCH 21/34] Added Frank's soulution... damn its fast! --- .../largestPrimePalindrome.js | 80 +++++++++++++++---- 1 file changed, 66 insertions(+), 14 deletions(-) diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 02f63b1..b996dd8 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -7,23 +7,75 @@ //Test 1000 => 929 -function isPrime(number) { - if (number < 2) {return false} - if (number != Math.round(number)) {return false} - let isPrime = true; - for (let i = 2; i <= Math.sqrt(number); i++) { - if (number % i == 0) {isPrime = false} +// WAY WAYYY faster +const largestPrimePalindrome = n => { + const isPrime = n => { + let divisor = 3, + limit = Math.sqrt(n); + + if (n === 2 || n === 3) return true; + if (n % 2 === 0) return false; + + while (divisor <= limit) { + if (n % divisor === 0) return false; + else divisor += 2; + } + return true; } - return isPrime; -} - -const longestPalindromePrime = (number) => { - for (let i = 0; i < number; i++){ - const test = number - i; - if (isPrime(test) && test === parseInt([...test.toString()].reverse().join(''))) { - return test + + const isPalindrome = n => { + let str = n.toString(), + len = str.length; + + for (let i = 0; i < len / 2; i++) { + if (str[i] !== str[len -1 -i]) + return false; } + return true; + } + + for (let i = n; i > 0; i--) { + if (isPrime(i) && isPalindrome(i)) return i; } } +console.log(largestPrimePalindrome(1000)); + +// // WAAAY Faster +// const longestPalindromePrime = (num) => { +// for (let i = num; i > 0; i--) { +// const str = i.toString(); +// if (str === str.split('').reverse().join('')) { +// let j = 2; +// let count = 0; +// while (count === 0 && j <= (i/2)) { +// if (i % j === 0) count++; +// j++; +// } +// if (count === 0) return i; +// } +// } +// }; + +// function isPrime(number) { +// if (number < 2) {return false} +// if (number != Math.round(number)) {return false} +// let isPrime = true; +// for (let i = 2; i <= Math.sqrt(number); i++) { +// if (number % i == 0) {isPrime = false} +// } +// return isPrime; +// } + +// const longestPalindromePrime = (number) => { +// for (let i = 0; i < number; i++){ +// const test = number - i; +// if (isPrime(test)) { +// if (test === parseInt([...test.toString()].reverse().join(''))) { +// return test +// } +// } +// } +// } + console.log(longestPalindromePrime(500)); \ No newline at end of file From ff35b79e3f89f0fe0754cb20261da07eb4195d4c Mon Sep 17 00:00:00 2001 From: phytertek Date: Sun, 20 Aug 2017 12:07:15 -0400 Subject: [PATCH 22/34] change --- brainTeasers/waterJugs.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/brainTeasers/waterJugs.md b/brainTeasers/waterJugs.md index 43cd5ab..4224800 100644 --- a/brainTeasers/waterJugs.md +++ b/brainTeasers/waterJugs.md @@ -16,4 +16,6 @@ You have a five-quart jug, a three-quart jug, and an unlimited supply of water ( # pour the 3 quarts into the 5 quart jug -# the 5 quart jug now contains 4 quarts \ No newline at end of file +# the 5 quart jug now contains 4 quarts + + From 914a32b2eb57d35fe24a8184b461bd4769c0ac39 Mon Sep 17 00:00:00 2001 From: phytertek Date: Sun, 20 Aug 2017 12:08:26 -0400 Subject: [PATCH 23/34] a change --- brainTeasers/waterJugs.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/brainTeasers/waterJugs.md b/brainTeasers/waterJugs.md index 4224800..7959353 100644 --- a/brainTeasers/waterJugs.md +++ b/brainTeasers/waterJugs.md @@ -17,5 +17,3 @@ You have a five-quart jug, a three-quart jug, and an unlimited supply of water ( # pour the 3 quarts into the 5 quart jug # the 5 quart jug now contains 4 quarts - - From 3526b5bb06216d06c784fd7571c4bfb079588435 Mon Sep 17 00:00:00 2001 From: phytertek Date: Tue, 22 Aug 2017 00:44:43 -0400 Subject: [PATCH 24/34] commonCharacters solution complete --- commonCharacters/commonCharacters.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/commonCharacters/commonCharacters.js b/commonCharacters/commonCharacters.js index ec31d82..8c3c42c 100644 --- a/commonCharacters/commonCharacters.js +++ b/commonCharacters/commonCharacters.js @@ -6,3 +6,21 @@ * Example: commonCharacters('acexivou', 'aegihobu') * * Returns: 'aeiou' */ +const test1 = 'acexivj oujdf'; +const test2 = 'aeg ihobujj'; + +const commonCharacters = (str1, str2) => { + const seen = {}; + let common = ''; + const matches = str1.match(new RegExp('(['+str2+'])', 'g')) + let length = matches.length + for (let i = 0; i < matches.length; i++){ + if (matches[i] !== ' ' && !seen[matches[i]]) { + common += matches[i]; + seen[matches[i]] = true; + } + } + return common +} + +console.log(commonCharacters(test1, test2)) \ No newline at end of file From b38cbb5498ffff4ff7aa4137950cfb97bf704e50 Mon Sep 17 00:00:00 2001 From: phytertek Date: Tue, 22 Aug 2017 10:30:57 -0400 Subject: [PATCH 25/34] fix typo in commonCharacters --- commonCharacters/commonCharacters.js | 1 - 1 file changed, 1 deletion(-) diff --git a/commonCharacters/commonCharacters.js b/commonCharacters/commonCharacters.js index 8c3c42c..1ef6611 100644 --- a/commonCharacters/commonCharacters.js +++ b/commonCharacters/commonCharacters.js @@ -13,7 +13,6 @@ const commonCharacters = (str1, str2) => { const seen = {}; let common = ''; const matches = str1.match(new RegExp('(['+str2+'])', 'g')) - let length = matches.length for (let i = 0; i < matches.length; i++){ if (matches[i] !== ' ' && !seen[matches[i]]) { common += matches[i]; From 46bcb5428843712c4e4a68125fbda0b58c31b1fb Mon Sep 17 00:00:00 2001 From: phytertek Date: Tue, 22 Aug 2017 12:25:01 -0400 Subject: [PATCH 26/34] evenOccurances challenge complete --- evenOccurences/evenOccurences.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index 35da569..7fcd06f 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -12,4 +12,21 @@ const evenOccurence = (arr) => { // Your code here. + const occ = {} + let returnVal; + for (let i = 0; i < arr.length; i++) { + if (occ[arr[i]]) occ[arr[i]]++; + else occ[arr[i]] = 1; + } + const occKeys = Object.keys(occ); + for (let j = 0; j < occKeys.length; j++) { + if(occ[occKeys[j]] % 2 === 0) { + returnVal = occKeys[j]; + break; + } + } + return returnVal; }; + +const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); +console.log(onlyEven); // 4 From 2d41d0434296ff17a774ddd65ee95d4d0f6b73ff Mon Sep 17 00:00:00 2001 From: phytertek Date: Tue, 22 Aug 2017 16:13:28 -0400 Subject: [PATCH 27/34] changed --- evenOccurences/evenOccurences.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index 7fcd06f..b4d11df 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -30,3 +30,6 @@ const evenOccurence = (arr) => { const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); console.log(onlyEven); // 4 + + + From 290f4028c190a06390be6c6e46654f0bfec3d183 Mon Sep 17 00:00:00 2001 From: phytertek Date: Tue, 22 Aug 2017 16:18:03 -0400 Subject: [PATCH 28/34] changed again --- evenOccurences/evenOccurences.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index b4d11df..72594e7 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -31,5 +31,3 @@ const evenOccurence = (arr) => { const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); console.log(onlyEven); // 4 - - From 54b539c3d538e4b6103ed6069bd682fc3449b777 Mon Sep 17 00:00:00 2001 From: phytertek Date: Wed, 23 Aug 2017 11:56:49 -0400 Subject: [PATCH 29/34] stringCompression complete --- stringCompression/stringCompression.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/stringCompression/stringCompression.js b/stringCompression/stringCompression.js index 48db571..e99a25e 100644 --- a/stringCompression/stringCompression.js +++ b/stringCompression/stringCompression.js @@ -4,3 +4,25 @@ // 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 test1 = 'aabcccccaaa' // => 'a2b1c5a3' +const test2 = 'aaaaaaaaaaaccccccdddddddefg' // => 'a11c6d7e1f1g1' +const test3 = 'AaaaBBbCcccDDDd'// 'AaaaBBbCcccDDDd' +const test4 = 'ABCDD'// => 'ABCDD' + +const compressor = (string) => { + const letters = [] + for(let i = 0; i < string.length; i++) { + if (i === 0 || string[i] !== string[i - 1]) { + letters.push(...[string[i], 1]) + } else { + letters[letters.length - 1]++ + } + } + return letters.length > string.length ? string : letters.join('') +} + +console.log(compressor(test1)) +console.log(compressor(test2)) +console.log(compressor(test3)) +console.log(compressor(test4)) \ No newline at end of file From 3aa2f844287a90ee875f7e28783f2db340f26047 Mon Sep 17 00:00:00 2001 From: phytertek Date: Thu, 24 Aug 2017 12:12:58 -0400 Subject: [PATCH 30/34] fix evenOccurance to account for ES6 Object traversal of integer keys --- evenOccurences/evenOccurences.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index 2378634..f497e6d 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -12,22 +12,24 @@ const evenOccurence = (arr) => { // Your code here. - const occ = {} - let returnVal; + const occurances = {} + let returnVal = null for (let i = 0; i < arr.length; i++) { - if (occ[arr[i]]) occ[arr[i]]++; - else occ[arr[i]] = 1; + if (occurances['0'+arr[i]]) occurances['0'+arr[i]]++; + else occurances['0'+arr[i]] = 1; } - const occKeys = Object.keys(occ); - for (let j = 0; j < occKeys.length; j++) { - if(occ[occKeys[j]] % 2 === 0) { - returnVal = occKeys[j]; + const occuranceKeys = Object.keys(occurances); + for (let j = 0; j < occuranceKeys.length; j++) { + if(occurances[occuranceKeys[j]] % 2 === 0) { + returnVal = occuranceKeys[j].splice(0,1); break; } } + Reflect return returnVal; }; -const onlyEven = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); +const onlyEven = evenOccurence([1, 7, 4, 2, 5, 1, 6, 8, 9, 6, 4, 3, 2, 1]); console.log(onlyEven); // 4 +console.log(evenOccurence([1,2,3,4,5])) \ No newline at end of file From c9be8b824e2a5eb5fdea7baab0e905d1b1a311e4 Mon Sep 17 00:00:00 2001 From: phytertek Date: Thu, 24 Aug 2017 12:13:20 -0400 Subject: [PATCH 31/34] vowelCount challenge complete --- vowelCount/vowelCount.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vowelCount/vowelCount.js b/vowelCount/vowelCount.js index 27fad79..a68f581 100644 --- a/vowelCount/vowelCount.js +++ b/vowelCount/vowelCount.js @@ -2,3 +2,7 @@ * Write a function that returns the count of the total number of vowels in a string. * Example: 'Hello World!' -> 3 */ + + const vowelCounter = str => str.match(/([aeiou])/g).length + + console.log(vowelCounter('Fuuuuuk')) \ No newline at end of file From d6f1032de0ae7b569926dcfa5e3fa0c068797f5c Mon Sep 17 00:00:00 2001 From: phytertek Date: Thu, 24 Aug 2017 12:27:07 -0400 Subject: [PATCH 32/34] fix vowelCount to ignore case in regex --- vowelCount/vowelCount.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vowelCount/vowelCount.js b/vowelCount/vowelCount.js index a68f581..e1d2e32 100644 --- a/vowelCount/vowelCount.js +++ b/vowelCount/vowelCount.js @@ -3,6 +3,6 @@ * Example: 'Hello World!' -> 3 */ - const vowelCounter = str => str.match(/([aeiou])/g).length + const vowelCounter = str => str.match(/([aeiou])/gi).length - console.log(vowelCounter('Fuuuuuk')) \ No newline at end of file + console.log(vowelCounter('FUuUuuuuuk')) \ No newline at end of file From dd3e22d4d44ebb95baf68bf90d199952c866e0a2 Mon Sep 17 00:00:00 2001 From: phytertek Date: Thu, 24 Aug 2017 15:21:08 -0400 Subject: [PATCH 33/34] Remove uneccessary if from stringCompression function --- stringCompression/stringCompression.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stringCompression/stringCompression.js b/stringCompression/stringCompression.js index e99a25e..b1715ef 100644 --- a/stringCompression/stringCompression.js +++ b/stringCompression/stringCompression.js @@ -13,7 +13,7 @@ const test4 = 'ABCDD'// => 'ABCDD' const compressor = (string) => { const letters = [] for(let i = 0; i < string.length; i++) { - if (i === 0 || string[i] !== string[i - 1]) { + if (string[i] !== string[i - 1]) { letters.push(...[string[i], 1]) } else { letters[letters.length - 1]++ From 624e0b05a5aac86e938456fa0a1ca64312f93cc0 Mon Sep 17 00:00:00 2001 From: phytertek Date: Fri, 25 Aug 2017 13:05:25 -0400 Subject: [PATCH 34/34] meanMedianMode challeng complete --- meanMedianMode/meanMedianMode.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/meanMedianMode/meanMedianMode.js b/meanMedianMode/meanMedianMode.js index 821fdc0..36021a8 100644 --- a/meanMedianMode/meanMedianMode.js +++ b/meanMedianMode/meanMedianMode.js @@ -2,3 +2,25 @@ * Given an array of numbers calculate the mean, median, and mode. * Return an object with properties for the mean, median, and mode. */ + + const mmmArr = (arr) => { + const o = {nums: {}, mean: 0, median: 0, mode: 0, maxOcc: 0}; + o.total = arr.reduce((t , v) => { + o.nums[v] ? o.nums[v]++ : o.nums[v] = 1; + if (o.nums[v] > o.maxOcc) { + o.maxOcc = o.nums[v]; + o.mode = v + } + o.mean = t / arr.length; + o.median = (arr.length / 2) % 2 ? + (arr[Math.ceil(arr.length / 2)] + arr[Math.floor(arr.length / 2)]) / 2 + : + arr[Math.floor(arr.length / 2) + 1] + return t + v + }) + return o; + } + + const someNums = [1,5,3,4,5,6,6,6,7,8,9,10,11,12,12,4,4] + const result = mmmArr(someNums) + console.log('Mean:', result.mean, 'Median:', result.median, 'Mode:', result.mode) \ No newline at end of file