From 968cd6c489130287ee0fd967c3916ae6000eeb53 Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 12 Aug 2020 10:24:41 -0700 Subject: [PATCH 001/103] inital pirate files --- medium/a-pirate-s-tale/code.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/medium/a-pirate-s-tale/code.js b/medium/a-pirate-s-tale/code.js index e1fd1c4c..d506d36f 100644 --- a/medium/a-pirate-s-tale/code.js +++ b/medium/a-pirate-s-tale/code.js @@ -1,5 +1,17 @@ function numberOfDays(coordinate) { - // Your code here. + let days = 0; + let daysTaken = 0; + for (let i = 0; i < coordinate.length; i++) { + if (coordinate[i] !== 0) { + if (days === 5) { + days = 0; + continue; + } + + days++ + } + } + return daysTaken; } module.exports = numberOfDays; From a23c2fbc26ac857eeb240492e2b96cf39576fd28 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 16 Aug 2020 10:24:21 -0700 Subject: [PATCH 002/103] accumlate product complete --- medium/accumulating-product/code.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/medium/accumulating-product/code.js b/medium/accumulating-product/code.js index f31214c4..c1d28ee1 100644 --- a/medium/accumulating-product/code.js +++ b/medium/accumulating-product/code.js @@ -1,5 +1,11 @@ function accumulatingProduct(arr) { - // Your code here. + let accumulate = 0; + const newArray = []; + for (let i = 0; i < arr.length; i++) { + accumulate *= arr[i]; + newArray.push(accumulate); + } + return newArray; } module.exports = accumulatingProduct; From e1ccc68720bad6c70910040782a6c193ceb27300 Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 17 Aug 2020 10:49:00 -0700 Subject: [PATCH 003/103] algrebra sequence exercise complete --- medium/algebra-sequence-boxes/code.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/medium/algebra-sequence-boxes/code.js b/medium/algebra-sequence-boxes/code.js index 28b7ccbf..043d0042 100644 --- a/medium/algebra-sequence-boxes/code.js +++ b/medium/algebra-sequence-boxes/code.js @@ -1,5 +1,16 @@ function boxSeq(step) { - // Your code here. + let currentNumber = 0; + if (step === 0) { + return currentNumber; + } + for(let i = 1; i <= step; i++) { + if (i % 2 === 1) { + currentNumber += 3 + } else { + currentNumber -= 1; + } + } + return currentNumber; } module.exports = boxSeq; From 30bfe6cf2741684d4e3116d93fdc8037427dbde0 Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 18 Aug 2020 11:45:04 -0700 Subject: [PATCH 004/103] all about string exercise complete --- medium/all-about-strings/code.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/medium/all-about-strings/code.js b/medium/all-about-strings/code.js index 93aeaa0d..a452924b 100644 --- a/medium/all-about-strings/code.js +++ b/medium/all-about-strings/code.js @@ -1,5 +1,32 @@ function allAboutStrings(str) { - // Your code here. + const arr = []; + const letters = []; + let repeat = false; + arr.push(str.length); + arr.push(str.substring(0, 1)); + arr.push(str.substring(str.length - 1)); + if(str.length % 2 === 1) { + arr.push(str.substr((str.length - 1) / 2, 1)) + } else { + arr.push(str.substr(((str.length - 1) / 2), 2)) + } + + for (let i = 0; i < str.length; i++) { + if (letters.includes(str[i])) { + arr.push(`@ index ${i}`) + repeat = true; + break; + } else { + letters.push(str[i]) + } + } + + if (!repeat) { + arr.push("not found"); + } + + console.log(arr) + return arr; } module.exports = allAboutStrings; From eb1c46273663a947e6208bcb1c578d4e7d607562 Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 19 Aug 2020 09:31:38 -0700 Subject: [PATCH 005/103] alternating cap ex complete --- medium/alternating-caps/code.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/medium/alternating-caps/code.js b/medium/alternating-caps/code.js index 0385f3ea..1f6ee319 100644 --- a/medium/alternating-caps/code.js +++ b/medium/alternating-caps/code.js @@ -1,5 +1,14 @@ function alternatingCaps(str) { - // Your code here. + let word = "" + for (let i = 0; i < str.length; i++) { + const letter = str[i]; + if (i % 2 === 0) { + word += letter.toUpperCase(); + } else { + word += letter.toLowerCase(); + } + } + return word; } module.exports = alternatingCaps; From 96c2a39d5ea6b1a9d8dc221930a3b7151a49ea14 Mon Sep 17 00:00:00 2001 From: John Ko Date: Thu, 20 Aug 2020 09:49:55 -0700 Subject: [PATCH 006/103] alternate zero and ones complete --- medium/alternating-ones-and-zeroes/code.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/medium/alternating-ones-and-zeroes/code.js b/medium/alternating-ones-and-zeroes/code.js index 9bec6fc3..eb7e9869 100644 --- a/medium/alternating-ones-and-zeroes/code.js +++ b/medium/alternating-ones-and-zeroes/code.js @@ -1,5 +1,19 @@ function canAlternate(s) { - // Your code here. + let zeros = 0; + let ones = 0; + for (let i = 0; i < s.length; i++) { + if (s[i] === "0") { + zeros++; + } else { + ones++; + } + } + const difference = zeros - ones; + if (difference > 1 || difference < -1) { + return false; + } else { + return true; + } } module.exports = canAlternate; From 3a2f6b5c744b9c647ce64ffca8fa154214bd6121 Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 21 Aug 2020 09:45:01 -0700 Subject: [PATCH 007/103] alliteration complete --- medium/amazing-alliteration/code.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/medium/amazing-alliteration/code.js b/medium/amazing-alliteration/code.js index 6562cca0..90192423 100644 --- a/medium/amazing-alliteration/code.js +++ b/medium/amazing-alliteration/code.js @@ -1,5 +1,20 @@ function alliterationCorrect(sentence) { - // Your code here. + const words = sentence.split(" "); + const letters = []; + let sameLetter = '' + for (let i = 0; i < words.length; i++) { + if (words[i].length > 3) { + const currentLetter = words[i].substr(0, 1).toLowerCase(); + letters.push(currentLetter); + if (sameLetter === '') { + sameLetter = letters[0].toLowerCase(); + } + if (sameLetter !== currentLetter) { + return false; + } + } + } + return true; } module.exports = alliterationCorrect; From f62ba67dbf64f11b6e51c00bc4b74c56ee1be90b Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 22 Aug 2020 10:37:34 -0700 Subject: [PATCH 008/103] are letters in second string present in first complete --- .../code.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/medium/are-letters-in-the-second-string-present-in-the-first/code.js b/medium/are-letters-in-the-second-string-present-in-the-first/code.js index 65d77376..3855966f 100644 --- a/medium/are-letters-in-the-second-string-present-in-the-first/code.js +++ b/medium/are-letters-in-the-second-string-present-in-the-first/code.js @@ -1,5 +1,12 @@ function letterCheck(arr) { - // Your code here. + const firstWord = arr[0].toLowerCase(); + const secondWord = arr[1].toLowerCase(); + for (let i = 0; i < secondWord.length; i++) { + if (!firstWord.includes(secondWord[i])) { + return false; + } + } + return true; } module.exports = letterCheck; From 16aad2770b0063b72bea2d05c341c08840bb4dbd Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 23 Aug 2020 12:16:02 -0700 Subject: [PATCH 009/103] atm exercise done --- medium/atm-pin-code-validation/code.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/medium/atm-pin-code-validation/code.js b/medium/atm-pin-code-validation/code.js index bcc167b9..65247d64 100644 --- a/medium/atm-pin-code-validation/code.js +++ b/medium/atm-pin-code-validation/code.js @@ -1,5 +1,16 @@ function validatePIN(pin) { - // Your code here. + if (pin.length !== 4 && pin.length !==6) { + return false; + } + const parsed = parseInt(pin); + if (parsed < 1000) { + return false; + } + if (isNaN(parsed)) { + return false + } else { + return true + } } module.exports = validatePIN; From f366c7df1e09ecf7593c791787b76b85f3fbf7de Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 24 Aug 2020 11:57:22 -0700 Subject: [PATCH 010/103] automorphic number complete --- medium/automorphic-numbers/code.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/medium/automorphic-numbers/code.js b/medium/automorphic-numbers/code.js index 697a5a44..df4ca320 100644 --- a/medium/automorphic-numbers/code.js +++ b/medium/automorphic-numbers/code.js @@ -1,5 +1,15 @@ function isAutomorphic(n) { - // Your code here. + const nString = "" + n; + const nLength = nString.length + const nSquared = n * n; + const nSquaredString = "" + nSquared; + const endPoint = nSquaredString.length-nLength; + const compare = nSquaredString.substr(endPoint, nLength) + if (parseInt(compare) === n) { + return true; + } else { + return false; + } } module.exports = isAutomorphic; From e46ecc5d4b96944a97cbeb26a9d13bcf5cdb85f4 Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 25 Aug 2020 09:16:57 -0700 Subject: [PATCH 011/103] barbecue challenge complete --- medium/barbecue-skewers/code.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/medium/barbecue-skewers/code.js b/medium/barbecue-skewers/code.js index 5898cfad..2449c893 100644 --- a/medium/barbecue-skewers/code.js +++ b/medium/barbecue-skewers/code.js @@ -1,5 +1,17 @@ function bbqSkewers(grill) { - // Your code here. + let veggie = 0; + let nonVeggie = 0; + const portions = []; + for (let i = 0; i < grill.length; i ++) { + if (!grill[i].includes("x")) { + veggie++; + } else { + nonVeggie++; + } + } + portions.push(veggie); + portions.push(nonVeggie); + return portions; } module.exports = bbqSkewers; From d683341852fa5e9f41d6e0cabc426880e2194060 Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 26 Aug 2020 09:16:34 -0700 Subject: [PATCH 012/103] basic email validation complete --- medium/basic-e-mail-validation/code.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/medium/basic-e-mail-validation/code.js b/medium/basic-e-mail-validation/code.js index e813c01b..45a11e13 100644 --- a/medium/basic-e-mail-validation/code.js +++ b/medium/basic-e-mail-validation/code.js @@ -1,5 +1,15 @@ function validateEmail(str) { - // Your code here. + const dotCom = str.substring(str.length - 4, str.length); + if (!str.includes("@")) { + return false; + } + if (str[0] === "@") { + return false; + } + if (dotCom !== ".com") { + return false; + } + return true; } module.exports = validateEmail; From 78d33ba257c85763f897496bc74213532a380f91 Mon Sep 17 00:00:00 2001 From: John Ko Date: Thu, 27 Aug 2020 09:00:14 -0700 Subject: [PATCH 013/103] bird names abbrev complete --- .../code.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/medium/bird-names-to-four-letter-bird-codes/code.js b/medium/bird-names-to-four-letter-bird-codes/code.js index 4bb03e8c..5b49b76c 100644 --- a/medium/bird-names-to-four-letter-bird-codes/code.js +++ b/medium/bird-names-to-four-letter-bird-codes/code.js @@ -1,5 +1,23 @@ function birdCode(arr) { - // Your code here. + const newArray = []; + for (let i = 0; i < arr.length; i++) { + const birdName = arr[i].replace("-", " ").split(" "); + if (birdName.length === 1) { + newArray.push(birdName[0].substr(0, 4).toUpperCase()); + } else if (birdName.length === 2) { + const birdAbbrev = birdName[0].substr(0, 2) + birdName[1].substr(0, 2); + newArray.push(birdAbbrev.toUpperCase()); + } else if (birdName.length === 3) { + const birdAbbrev = birdName[0].substr(0, 1) + birdName[1].substr(0, 1) + + birdName[2].substr(0, 2); + newArray.push(birdAbbrev.toUpperCase()); + } else if (birdName.length === 4) { + const birdAbbrev = birdName[0].substr(0, 1) + birdName[1].substr(0, 1) + + birdName[2].substr(0, 1) + birdName[3].substr(0, 1); + newArray.push(birdAbbrev.toUpperCase()); + } + } + return newArray; } module.exports = birdCode; From 2fa375b2581154e46d30eacec74cf9f77d7b892e Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 28 Aug 2020 09:39:35 -0700 Subject: [PATCH 014/103] blackjack exercise complete --- medium/blackjack/code.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/medium/blackjack/code.js b/medium/blackjack/code.js index 081200b7..7973c91f 100644 --- a/medium/blackjack/code.js +++ b/medium/blackjack/code.js @@ -1,5 +1,26 @@ function overTwentyOne(cards) { - // Your code here. + let sum = 0; + let hasAce = false; + for (let i = 0; i < cards.length; i++) { + if (cards[i] === "J" || cards[i] === "Q" || cards[i] === "K") { + sum += 10; + } else if (cards[i] === "A") { + hasAce = true; + } else { + sum += cards[i]; + } + } + if(hasAce) { + if ((sum + 11) > 21) { + sum += 1; + } else { + sum +=11; + } + } + if (sum > 21) { + return true; + } + return false; } module.exports = overTwentyOne; From 419f2364add1e3f743a05f89c7da478bcbf77167 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 29 Aug 2020 01:55:34 -0700 Subject: [PATCH 015/103] box exercise complete --- medium/box-completely-filled/code.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/medium/box-completely-filled/code.js b/medium/box-completely-filled/code.js index f45bff51..1fdafa11 100644 --- a/medium/box-completely-filled/code.js +++ b/medium/box-completely-filled/code.js @@ -1,5 +1,14 @@ function completelyFilled(arr) { - // Your code here. + const boxLength = arr[0].length; + if (boxLength < 3) { + return true; + } + for (let i = 0; i < arr.length; i++) { + if (arr[i].includes(" ")) { + return false; + } + } + return true; } module.exports = completelyFilled; From 84b066684cf8b40ae74bf7c72399800c81c3ceff Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 30 Aug 2020 09:42:45 -0700 Subject: [PATCH 016/103] calculate the difference complete --- .../code.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/medium/calculate-the-difference-between-two-numbers/code.js b/medium/calculate-the-difference-between-two-numbers/code.js index 709bca91..ffa2136f 100644 --- a/medium/calculate-the-difference-between-two-numbers/code.js +++ b/medium/calculate-the-difference-between-two-numbers/code.js @@ -1,5 +1,13 @@ function percentDiff(num1, num2) { - // Your code here. + let difference = 0; + if (num1 > num2) { + difference = num1 - num2; + } else { + difference = num2 - num1; + } + const average = (num1 + num2) / 2 + const percent = ((difference / average) * 100).toFixed(1); + return (parseFloat(percent)) } module.exports = percentDiff; From 517311fd95cb0cca04afe75e0630eb19c390675b Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 31 Aug 2020 11:25:26 -0700 Subject: [PATCH 017/103] calculate distance complete --- .../code.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/medium/calculate-the-shortest-distance-between-2-points/code.js b/medium/calculate-the-shortest-distance-between-2-points/code.js index 836d13ad..fc088ed6 100644 --- a/medium/calculate-the-shortest-distance-between-2-points/code.js +++ b/medium/calculate-the-shortest-distance-between-2-points/code.js @@ -1,5 +1,14 @@ function shortestDistance(str) { - // Your code here. + const arr = str.split(","); + for(let i = 0; i < arr.length; i++) { + arr[i] = parseInt(arr[i]); + } + const xDiffer = arr[2] - arr[0]; + const yDiffer = arr[3] - arr[1]; + + const differ = xDiffer * xDiffer + yDiffer * yDiffer; + + return parseFloat(Math.sqrt(differ).toFixed(2)); } module.exports = shortestDistance; From c362b8b7a8bc884cdd8cfd31fe8b4db959fbdc30 Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 1 Sep 2020 08:58:14 -0700 Subject: [PATCH 018/103] capitalize first letter complete --- medium/capitalize-the-first-letter-of-each-word/code.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/medium/capitalize-the-first-letter-of-each-word/code.js b/medium/capitalize-the-first-letter-of-each-word/code.js index 87c4a4a9..40036f1e 100644 --- a/medium/capitalize-the-first-letter-of-each-word/code.js +++ b/medium/capitalize-the-first-letter-of-each-word/code.js @@ -1,5 +1,10 @@ function makeTitle(str) { - // Your code here. + const arr = str.split(" "); + for (let i = 0; i < arr.length; i++) { + arr[i] = arr[i][0].toUpperCase() + arr[i].substring(1) + } + const newStr = arr.join(" ") + return newStr; } module.exports = makeTitle; From 650e360020da421720f6dba66d7443254a9580fb Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 2 Sep 2020 09:55:28 -0700 Subject: [PATCH 019/103] capitalize name complete --- medium/capitalize-the-names/code.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/medium/capitalize-the-names/code.js b/medium/capitalize-the-names/code.js index fb606828..7c844971 100644 --- a/medium/capitalize-the-names/code.js +++ b/medium/capitalize-the-names/code.js @@ -1,5 +1,10 @@ function capMe(arr) { - // Your code here. + const newArr = []; + for (let i = 0; i < arr.length; i++) { + const word = arr[i][0].toUpperCase() + arr[i].substring(1).toLowerCase(); + newArr.push(word) + } + return newArr; } module.exports = capMe; From a0b6a3dd6e156f1450b63f57b51e469b95da569e Mon Sep 17 00:00:00 2001 From: John Ko Date: Thu, 3 Sep 2020 10:09:07 -0700 Subject: [PATCH 020/103] anagram challenge complete --- medium/check-for-anagrams/code.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/medium/check-for-anagrams/code.js b/medium/check-for-anagrams/code.js index da2955bb..8509ee4b 100644 --- a/medium/check-for-anagrams/code.js +++ b/medium/check-for-anagrams/code.js @@ -1,5 +1,19 @@ function isAnagram(s1, s2) { - // Your code here. + const word1 = s1.toLowerCase().split(""); + const word2 = s2.toLowerCase().split(""); + for(let i = 0; i < word1.length; i++) { + if (!word2.includes(word1[i])) { + return false; + } else { + const index = word2.indexOf(word1[i]) + word2.splice(index, 1) + } + } + if (word2.length === 0) { + return true; + } else { + return false; + } } module.exports = isAnagram; From fa91b79acfe2a9c350d65afdca895306aa77507c Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 4 Sep 2020 09:32:50 -0700 Subject: [PATCH 021/103] check prime number complete --- medium/check-if-a-number-is-prime/code.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/medium/check-if-a-number-is-prime/code.js b/medium/check-if-a-number-is-prime/code.js index ffdcef1c..73a70957 100644 --- a/medium/check-if-a-number-is-prime/code.js +++ b/medium/check-if-a-number-is-prime/code.js @@ -1,5 +1,13 @@ function isPrime(num) { - // Your code here. + if (num === 1) { + return false; + } + for (let i = 2; i < num; i++) { + if(num % i === 0) { + return false; + } + } + return true; } module.exports = isPrime; From f78a87a2bd45d0616b3beb1222be7b5706ac9100 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 5 Sep 2020 12:54:02 -0700 Subject: [PATCH 022/103] check array done --- medium/check-if-one-array-is-subset-of-another/code.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/medium/check-if-one-array-is-subset-of-another/code.js b/medium/check-if-one-array-is-subset-of-another/code.js index e05aa8bd..a7e09f8b 100644 --- a/medium/check-if-one-array-is-subset-of-another/code.js +++ b/medium/check-if-one-array-is-subset-of-another/code.js @@ -1,5 +1,13 @@ function subset(arr1, arr2) { - // Your code here. + for(let i = 0; i < arr1.length; i++) { + if (!arr2.includes(arr1[i])) { + return false; + } else { + const index = arr2.indexOf(arr1[i]) + arr2.splice(index, 1) + } + } + return true; } module.exports = subset; From f4b5aa5e54ba1f89f7d82333cce813c3343afb99 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 6 Sep 2020 09:22:14 -0700 Subject: [PATCH 023/103] inital files for palindrome --- medium/check-if-the-string-is-a-palindrome/code.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/medium/check-if-the-string-is-a-palindrome/code.js b/medium/check-if-the-string-is-a-palindrome/code.js index be712559..28eee88d 100644 --- a/medium/check-if-the-string-is-a-palindrome/code.js +++ b/medium/check-if-the-string-is-a-palindrome/code.js @@ -1,5 +1,6 @@ function isPalindrome(str) { - // Your code here. + let newStr = str.replace(" ", ""); + console.log(newStr, str) } module.exports = isPalindrome; From a6068a60fe67ac795df1d7189fdf2205370b39ed Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 7 Sep 2020 10:34:37 -0700 Subject: [PATCH 024/103] check palindrome complete --- medium/check-if-the-string-is-a-palindrome/code.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/medium/check-if-the-string-is-a-palindrome/code.js b/medium/check-if-the-string-is-a-palindrome/code.js index 28eee88d..f80bf82c 100644 --- a/medium/check-if-the-string-is-a-palindrome/code.js +++ b/medium/check-if-the-string-is-a-palindrome/code.js @@ -1,6 +1,12 @@ function isPalindrome(str) { - let newStr = str.replace(" ", ""); - console.log(newStr, str) + let newStr = str.replace(/ /g, "").replace(/,/g, "").replace(/[^\w]/g, "").toLowerCase(); + const strLength = newStr.length - 1; + for (let i = 0; i < newStr.length; i++) { + if(newStr[i] !== newStr[strLength - i]) { + return false; + } + } + return true; } module.exports = isPalindrome; From 8b650cdf01dad1541eaef8cbf4a6d20e17685123 Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 8 Sep 2020 10:17:24 -0700 Subject: [PATCH 025/103] chocolate excercise complete --- medium/chocolate-dilemma/code.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/medium/chocolate-dilemma/code.js b/medium/chocolate-dilemma/code.js index 28b110fa..385efb24 100644 --- a/medium/chocolate-dilemma/code.js +++ b/medium/chocolate-dilemma/code.js @@ -1,5 +1,18 @@ function testFairness(agatha, bertha) { - // Your code here. + let agathaChoco = 0; + let berthaChoco = 0; + for (let i = 0; i < agatha.length; i++) { + agathaChoco += agatha[i][0] * agatha[i][1]; + } + for (let i = 0; i < bertha.length; i++) { + berthaChoco += bertha[i][0] * bertha[i][1]; + } + + if (agathaChoco === berthaChoco) { + return true; + } else { + return false; + } } module.exports = testFairness; From 4912be6322b4861971aa7b3d411340c392e163af Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 9 Sep 2020 13:51:10 -0700 Subject: [PATCH 026/103] attempted tree --- medium/christmas-tree/code.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/medium/christmas-tree/code.js b/medium/christmas-tree/code.js index 91af3656..819ce2a7 100644 --- a/medium/christmas-tree/code.js +++ b/medium/christmas-tree/code.js @@ -1,5 +1,28 @@ function tree(h) { - // Your code here. + const cTree = []; + if(h === 1) { + cTree.push("#") + return cTree; + } + for (let i = 1; i < h + 1; i++) { + let layer = ""; + for (let k = 1; k < h - i ; k++) { + layer += " "; + } + for (let j = 0; j < h; j++) { + if (j === 0) { + layer += "#"; + } else { + layer += "##" + } + } + for (let k = 1; k < h - i; k++) { + layer += " "; + } + console.log(cTree) + cTree.push(layer); + } + return cTree; } module.exports = tree; From a0919d7f19e19ce62143155d3cd1f6f99e51ad02 Mon Sep 17 00:00:00 2001 From: John Ko Date: Thu, 10 Sep 2020 08:09:43 -0700 Subject: [PATCH 027/103] attempted tree --- medium/christmas-tree/code.js | 1 - 1 file changed, 1 deletion(-) diff --git a/medium/christmas-tree/code.js b/medium/christmas-tree/code.js index 819ce2a7..5680b810 100644 --- a/medium/christmas-tree/code.js +++ b/medium/christmas-tree/code.js @@ -19,7 +19,6 @@ function tree(h) { for (let k = 1; k < h - i; k++) { layer += " "; } - console.log(cTree) cTree.push(layer); } return cTree; From 4cbcd4198d516a4b3c15a5552f227d72c4de926e Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 11 Sep 2020 08:10:38 -0700 Subject: [PATCH 028/103] attempted tree --- medium/christmas-tree/code.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/medium/christmas-tree/code.js b/medium/christmas-tree/code.js index 5680b810..206a3ec9 100644 --- a/medium/christmas-tree/code.js +++ b/medium/christmas-tree/code.js @@ -1,22 +1,18 @@ function tree(h) { const cTree = []; - if(h === 1) { - cTree.push("#") - return cTree; - } for (let i = 1; i < h + 1; i++) { let layer = ""; - for (let k = 1; k < h - i ; k++) { + for (let k = 0; k < h - i ; k++) { layer += " "; } - for (let j = 0; j < h; j++) { + for (let j = 0; j < i; j++) { if (j === 0) { layer += "#"; } else { layer += "##" } } - for (let k = 1; k < h - i; k++) { + for (let k = 0; k < h - i; k++) { layer += " "; } cTree.push(layer); From e720436f710abde25a666d228dd5a470b19fb166 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 12 Sep 2020 10:04:51 -0700 Subject: [PATCH 029/103] Compoundiing letters --- medium/compounding-letters/code.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/medium/compounding-letters/code.js b/medium/compounding-letters/code.js index 6db4c4bf..9b17cc80 100644 --- a/medium/compounding-letters/code.js +++ b/medium/compounding-letters/code.js @@ -1,5 +1,19 @@ function accum(str) { - // Your code here. + const arr = str.split(""); + let word = ""; + for (let i = 0; i < arr.length; i++) { + for( let k = 0; k <= i; k++) { + if ( k === 0) { + word += arr[i].toUpperCase(); + } else { + word += arr[i].toLowerCase(); + } + } + if(i !== arr.length - 1) { + word += "-" + } + } + return word; } module.exports = accum; From d39f6e1f7dc68e54fa23df93765ebcd80a24db76 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 13 Sep 2020 00:49:04 -0700 Subject: [PATCH 030/103] convenience complete --- medium/convenience-store/code.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/medium/convenience-store/code.js b/medium/convenience-store/code.js index a837e61a..481f879c 100644 --- a/medium/convenience-store/code.js +++ b/medium/convenience-store/code.js @@ -1,5 +1,21 @@ function changeEnough(change, amountDue) { - // Your code here. + let totalChange = 0; + for (let i = 0; i < change.length; i++) { + if (i === 0) { + totalChange += change[i] * .25; + } else if (i === 1) { + totalChange += change[i] * .10; + } else if (i === 2) { + totalChange += change[i] * .05; + } else { + totalChange += change[i] * .01; + } + } + if (totalChange >= amountDue) { + return true; + } else { + return false; + } } module.exports = changeEnough; From 5b85ad3ca9d8a520ea0b909e44bf8a626fd041b6 Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 14 Sep 2020 01:11:58 -0700 Subject: [PATCH 031/103] convert key values to array --- medium/convert-key-values-in-an-object-to-array/code.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/medium/convert-key-values-in-an-object-to-array/code.js b/medium/convert-key-values-in-an-object-to-array/code.js index 50658430..a6b0443e 100644 --- a/medium/convert-key-values-in-an-object-to-array/code.js +++ b/medium/convert-key-values-in-an-object-to-array/code.js @@ -1,5 +1,6 @@ function objectToArray(obj) { - // Your code here. + const entries = Object.entries(obj); + return entries; } module.exports = objectToArray; From baa898b5ca34b0c2941958b5c8ef3b547ea03d40 Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 15 Sep 2020 03:28:27 -0700 Subject: [PATCH 032/103] convert number complete --- .../code.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/medium/convert-zero-and-one-text-to-1-and-0/code.js b/medium/convert-zero-and-one-text-to-1-and-0/code.js index 7e13c767..68abe3e3 100644 --- a/medium/convert-zero-and-one-text-to-1-and-0/code.js +++ b/medium/convert-zero-and-one-text-to-1-and-0/code.js @@ -1,5 +1,22 @@ function textToNumberBinary(str) { - // Your code here. + let binary = ""; + const words = str.split(" ") + for (let i = 0; i < words.length; i++) { + const match = words[i].toLowerCase(); + if (match === "zero") { + binary += 0; + } else if (match === "ten") { + binary += 10; + } else { + binary += 1; + } + } + console.log(binary, typeof(binary), binary.length) + if (binary.length % 8 === 0) { + return binary; + } else { + return ""; + } } module.exports = textToNumberBinary; From 82f8c90ef7ddbcb0ee1039357a8d2a2bc62b9d88 Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 16 Sep 2020 02:08:51 -0700 Subject: [PATCH 033/103] count letter --- medium/count-letters-in-a-word-search/code.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/medium/count-letters-in-a-word-search/code.js b/medium/count-letters-in-a-word-search/code.js index 7661d0f9..372feea0 100644 --- a/medium/count-letters-in-a-word-search/code.js +++ b/medium/count-letters-in-a-word-search/code.js @@ -1,5 +1,13 @@ function letterCounter(arr, letter) { - // Your code here. + let count = 0; + for (let i = 0; i < arr.length; i++) { + for (let k = 0; k < arr[i].length; k++) { + if (arr[i][k] === letter) { + count ++; + } + } + } + return count; } module.exports = letterCounter; From a9977e1fbc5ac9f92d0fba67450d2fdd973de7f4 Mon Sep 17 00:00:00 2001 From: John Ko Date: Thu, 17 Sep 2020 00:42:32 -0700 Subject: [PATCH 034/103] count one binary --- .../code.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/medium/count-ones-in-binary-representation-of-integer/code.js b/medium/count-ones-in-binary-representation-of-integer/code.js index 5eec5af1..a0622779 100644 --- a/medium/count-ones-in-binary-representation-of-integer/code.js +++ b/medium/count-ones-in-binary-representation-of-integer/code.js @@ -1,5 +1,13 @@ function countOnes(i) { - // Your code here. + let countOne = 0; + const binary = i.toString(2) + "" + const binaryNumber = binary.split(""); + for(let i = 0; i < binaryNumber.length; i++) { + if (binaryNumber[i] === "1") { + countOne++; + } + } + return countOne } module.exports = countOnes; From 3d605f162840dce90e888a0b79262cdec1d63221 Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 18 Sep 2020 02:14:54 -0700 Subject: [PATCH 035/103] count letters and digits --- medium/count-the-letters-and-digits/code.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/medium/count-the-letters-and-digits/code.js b/medium/count-the-letters-and-digits/code.js index 55445d54..61793392 100644 --- a/medium/count-the-letters-and-digits/code.js +++ b/medium/count-the-letters-and-digits/code.js @@ -1,5 +1,20 @@ function countAll(str) { - // Your code here. + const letters = str.split("") + const count = {} + let lettersCount = 0; + let numberCount = 0; + for (let i = 0; i < letters.length; i++) { + if (isNaN(letters[i])) { + lettersCount++; + } else if (letters[i] === " ") { + continue; + } else { + numberCount++ + } + } + count.LETTERS = lettersCount; + count.DIGITS = numberCount; + return count; } module.exports = countAll; From 4066e76f5d05f28950a0175a50804a97a8b13ac9 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 19 Sep 2020 03:30:09 -0700 Subject: [PATCH 036/103] count dup complete --- .../code.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/medium/count-the-number-of-duplicate-characters/code.js b/medium/count-the-number-of-duplicate-characters/code.js index 921ca2cf..51fc05d9 100644 --- a/medium/count-the-number-of-duplicate-characters/code.js +++ b/medium/count-the-number-of-duplicate-characters/code.js @@ -1,5 +1,19 @@ function duplicateCount(str) { - // Your code here. + const countDup = {}; + let count = 0; + for (let i = 0; i < str.length; i++) { + if (countDup.hasOwnProperty(str[i])) { + countDup[str[i]]++; + } else { + countDup[str[i]] = 1; + } + } + for (const property in countDup) { + if (countDup[property] > 1) { + count++; + } + } + return count; } module.exports = duplicateCount; From 89066db6ce04c0951702832aac7dafbaac9b57a3 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 20 Sep 2020 09:23:54 -0700 Subject: [PATCH 037/103] cumulative array sum complete --- medium/cumulative-array-sum/code.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/medium/cumulative-array-sum/code.js b/medium/cumulative-array-sum/code.js index 683221ec..f40b7858 100644 --- a/medium/cumulative-array-sum/code.js +++ b/medium/cumulative-array-sum/code.js @@ -1,5 +1,11 @@ function cumulativeSum(arr) { - // Your code here. + let cumulative = 0; + const cumulativeArr = []; + for (let i = 0; i < arr.length; i++) { + cumulative += arr[i]; + cumulativeArr.push(cumulative) + } + return cumulativeArr; } module.exports = cumulativeSum; From 4fd10b0b75d48f9661129314aa35a3c19826345a Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 21 Sep 2020 00:59:52 -0700 Subject: [PATCH 038/103] delete extra elements --- .../code.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/medium/delete-occurrences-of-extra-elements-in-an-array/code.js b/medium/delete-occurrences-of-extra-elements-in-an-array/code.js index 637ad2e1..e5ad7661 100644 --- a/medium/delete-occurrences-of-extra-elements-in-an-array/code.js +++ b/medium/delete-occurrences-of-extra-elements-in-an-array/code.js @@ -1,5 +1,18 @@ function deleteOccurrences(arr, num) { - // Your code here. + const obj = {}; + const newArr = []; + for (let i = 0; i < arr.length; i++) { + if(obj.hasOwnProperty(arr[i])) { + obj[arr[i]]++; + + } else { + obj[arr[i]] = 1; + } + if (obj[arr[i]] <= num) { + newArr.push(arr[i]) + } + } + return newArr; } module.exports = deleteOccurrences; From f8b9a9ffb05d78f82e6c140b539b5847a213daf9 Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 22 Sep 2020 08:33:06 -0700 Subject: [PATCH 039/103] digit distance complete --- medium/digit-distance/code.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/medium/digit-distance/code.js b/medium/digit-distance/code.js index b8fdb958..72a0def5 100644 --- a/medium/digit-distance/code.js +++ b/medium/digit-distance/code.js @@ -1,5 +1,15 @@ function digitDistance(num1, num2) { - // Your code here. + const str1 = num1 + ""; + const str2 = num2 + ""; + let distance = 0; + for (let i = 0; i < str1.length; i++) { + let difference = parseInt(str1[i]) - parseInt(str2[i]); + if (difference < 0) { + difference *= -1; + } + distance += difference; + } + return distance; } module.exports = digitDistance; From 28a7f77a8ee1e1f65cfb5460f2bdca44a8ebbf25 Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 23 Sep 2020 01:06:45 -0700 Subject: [PATCH 040/103] divide array complete --- medium/divide-array-into-chunks/code.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/medium/divide-array-into-chunks/code.js b/medium/divide-array-into-chunks/code.js index e84abf0f..d2e30d25 100644 --- a/medium/divide-array-into-chunks/code.js +++ b/medium/divide-array-into-chunks/code.js @@ -1,5 +1,16 @@ function chunkify(arr, size) { - // Your code here. + const newArr = []; + while (arr.length !== 0) { + const currentArr = []; + for (let i = 0; i < size; i++) { + if (arr.length === 0) { + break; + } + currentArr.push(arr.shift()); + } + newArr.push(currentArr) + } + return newArr; } module.exports = chunkify; From 222566a006a19935c48b0fe0f8d2d095bae79280 Mon Sep 17 00:00:00 2001 From: John Ko Date: Thu, 24 Sep 2020 00:00:30 -0700 Subject: [PATCH 041/103] double letter complete --- medium/double-letters/code.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/medium/double-letters/code.js b/medium/double-letters/code.js index 93b9b7db..3be4f8a8 100644 --- a/medium/double-letters/code.js +++ b/medium/double-letters/code.js @@ -1,5 +1,12 @@ function doubleLetters(word) { - // Your code here. + for (let i = 0; i < word.length; i++) { + if (i === word.length - 1) { + return false; + } + if (word[i] === word[i + 1]) { + return true; + } + } } module.exports = doubleLetters; From 6aaa24daacb9f7bc1587ca03e09953e427bfd21e Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 25 Sep 2020 08:08:16 -0700 Subject: [PATCH 042/103] equality of 3 complete --- medium/equality-of-3-values/code.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/medium/equality-of-3-values/code.js b/medium/equality-of-3-values/code.js index ce0c8185..a7aaedeb 100644 --- a/medium/equality-of-3-values/code.js +++ b/medium/equality-of-3-values/code.js @@ -1,5 +1,18 @@ function equal(a, b, c) { - // Your code here. + if (a === b) { + if (a === c) { + return 3; + } else { + return 2; + } + } else { + if (a === c) { + return 2; + } else if (b === c) { + return 2; + } + } + return 0; } module.exports = equal; From 423ed37fda08dbd2114dbdff48b8362efaf32154 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 26 Sep 2020 10:38:44 -0700 Subject: [PATCH 043/103] factorize complete --- medium/factorize-a-number/code.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/medium/factorize-a-number/code.js b/medium/factorize-a-number/code.js index 7eb5f693..cd29bf87 100644 --- a/medium/factorize-a-number/code.js +++ b/medium/factorize-a-number/code.js @@ -1,5 +1,11 @@ function factorize(num) { - // Your code here. + const factors = []; + for (let i = 1; i <= num; i++) { + if (num % i === 0) { + factors.push(i); + } + } + return factors; } module.exports = factorize; From f0930e6ebe37fc9a2ef04f29e9c79f57c3889e30 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 27 Sep 2020 01:49:46 -0700 Subject: [PATCH 044/103] fixed error value vs reference --- medium/fix-the-error-value-vs-reference-types/code.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/medium/fix-the-error-value-vs-reference-types/code.js b/medium/fix-the-error-value-vs-reference-types/code.js index ddb2b7e2..2770202b 100644 --- a/medium/fix-the-error-value-vs-reference-types/code.js +++ b/medium/fix-the-error-value-vs-reference-types/code.js @@ -1,5 +1,10 @@ function checkEquals(arr1, arr2) { - // Your code here. + for (let i = 0; i < arr1.length; i++) { + if (arr1[i] !== arr2[i]) { + return false; + } + } + return true; } module.exports = checkEquals; From 3ab1007fd1c3d1693b6a689647d0ad8b7ad7f8b0 Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 28 Sep 2020 00:35:19 -0700 Subject: [PATCH 045/103] flash card complete --- medium/flash-cards/code.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/medium/flash-cards/code.js b/medium/flash-cards/code.js index 8c2e7b58..8c1d06bc 100644 --- a/medium/flash-cards/code.js +++ b/medium/flash-cards/code.js @@ -1,5 +1,19 @@ function flash([num1, op, num2]) { - // Your code here. + switch (op) { + case "+": + return num1 + num2; + case "-": + return num1 - num2; + case "x": + return num1 * num2; + case "/": + if(num2 === 0) { + return undefined; + } + return parseFloat((num1 / num2).toFixed(2)); + default: + return undefined; + } } module.exports = flash; From ca4732150a6ea1ecc1a413633e8c642658d3c7be Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 29 Sep 2020 09:13:08 -0700 Subject: [PATCH 046/103] format attempted --- .../code.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/medium/format-number-with-comma-s-separating-thousands/code.js b/medium/format-number-with-comma-s-separating-thousands/code.js index be8e9a2a..262edb74 100644 --- a/medium/format-number-with-comma-s-separating-thousands/code.js +++ b/medium/format-number-with-comma-s-separating-thousands/code.js @@ -1,5 +1,11 @@ function formatNum(num) { - // Your code here. + let number = (num + "").split(""); + console.log(number) + for (let i = number.length - 1; i > 0; i - 3) { + number.splice(i, ","); + } + const result = number.join("") + return result; } module.exports = formatNum; From 8115958628bf3b656f340806ade8a34a3e1737fd Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 30 Sep 2020 00:25:53 -0700 Subject: [PATCH 047/103] frequency complete --- medium/frequency-distribution/code.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/medium/frequency-distribution/code.js b/medium/frequency-distribution/code.js index fcdb5fb7..1e55869a 100644 --- a/medium/frequency-distribution/code.js +++ b/medium/frequency-distribution/code.js @@ -1,5 +1,13 @@ function getFrequencies(arr) { - // Your code here. + const obj = {}; +for (let i = 0; i < arr.length; i++) { + if (obj.hasOwnProperty(arr[i])) { + obj[arr[i]]++; + } else { + obj[arr[i]] = 1; + } +} +return obj; } module.exports = getFrequencies; From c8e924e97ab566deae0f1c204c094b4e3b7f217a Mon Sep 17 00:00:00 2001 From: John Ko Date: Thu, 1 Oct 2020 08:54:36 -0700 Subject: [PATCH 048/103] generate attempted --- .../code.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/medium/generate-n-size-combinations-from-an-array/code.js b/medium/generate-n-size-combinations-from-an-array/code.js index e58e81f6..0a4807a1 100644 --- a/medium/generate-n-size-combinations-from-an-array/code.js +++ b/medium/generate-n-size-combinations-from-an-array/code.js @@ -1,5 +1,23 @@ function combo(arr, n) { - // Your code here. + const newArr = []; + if (arr.length < n) { + return newArr; + } + if (n === 0) { + newArr.push([]); + return newArr; + } + for(let i = 0; i < arr.length - 1; i++) { + for (let k = i + 1; k < arr.length; k++) { + const tempArr = [arr[i]]; + tempArr.push(arr[k]); + newArr.push(tempArr); + } + } + + console.log(newArr) + + return newArr; } module.exports = combo; From 89e6fa2eca0132ef0be5afed47487184badfb298 Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 2 Oct 2020 09:41:12 -0700 Subject: [PATCH 049/103] hitting the jackpot complete --- medium/hitting-the-jackpot/code.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/medium/hitting-the-jackpot/code.js b/medium/hitting-the-jackpot/code.js index eb950f14..3338f6e8 100644 --- a/medium/hitting-the-jackpot/code.js +++ b/medium/hitting-the-jackpot/code.js @@ -1,5 +1,14 @@ function testJackpot(result) { - // Your code here. + if (result[0] !== result[1]) { + return false; + } + if (result[0] !== result[2]) { + return false; + } + if (result[0] !== result[3]) { + return false; + } + return true; } module.exports = testJackpot; From 79797c10a8454b9c753d22756fbad3ec31f83bb8 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 3 Oct 2020 00:16:53 -0700 Subject: [PATCH 050/103] identical attempt --- medium/identical-subarrays/code.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/medium/identical-subarrays/code.js b/medium/identical-subarrays/code.js index 55481381..805c74ce 100644 --- a/medium/identical-subarrays/code.js +++ b/medium/identical-subarrays/code.js @@ -1,5 +1,21 @@ function countIdentical(arr) { - // Your code here. + let counter = 0; + for (let i = 0; i < arr.length; i++) { + if (arr[i].length === 1) { + counter++; + } else { + let equal = true; + for (let k = 1; k < arr[i].length; k++) { + if (arr[i][0] !== arr[i][k]) { + equal = false; + } + } + if (equal) { + counter++; + } + } + return counter; + } } module.exports = countIdentical; From ca047f173f01e7191bb1a3113ceb7db7b59c3ef1 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 4 Oct 2020 08:49:57 -0700 Subject: [PATCH 051/103] index multi complete --- medium/index-multiplier/code.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/medium/index-multiplier/code.js b/medium/index-multiplier/code.js index e863849c..72ae16b3 100644 --- a/medium/index-multiplier/code.js +++ b/medium/index-multiplier/code.js @@ -1,5 +1,9 @@ function indexMultiplier(arr) { - // Your code here. + let total = 0; + for (let i = 0; i < arr.length; i++) { + total += (i * arr[i]) + } + return total; } module.exports = indexMultiplier; From 2fb3fc1aab738df0ca4b71988df2610f7c929f8b Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 11 Nov 2020 23:49:24 -0800 Subject: [PATCH 052/103] index shuffle complete --- easy/index-shuffle/code.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/easy/index-shuffle/code.js b/easy/index-shuffle/code.js index fabc3dd0..5fc6bc96 100644 --- a/easy/index-shuffle/code.js +++ b/easy/index-shuffle/code.js @@ -1,5 +1,14 @@ function indexShuffle(str) { - // Your code here. + let evenIndex = ""; + let oddIndex = ""; + for (let i = 0; i < str.length; i++) { + if (i % 2 === 0) { + evenIndex += str[i]; + } else { + oddIndex += str[i]; + } + } + return evenIndex + oddIndex; } module.exports = indexShuffle; From b43b1e5ed761e788c1b245524c9bd0310b7762b8 Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 13 Nov 2020 00:05:46 -0800 Subject: [PATCH 053/103] joini two portion complete --- easy/join-two-portions-of-a-path/code.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/easy/join-two-portions-of-a-path/code.js b/easy/join-two-portions-of-a-path/code.js index fd371eba..f9b9033e 100644 --- a/easy/join-two-portions-of-a-path/code.js +++ b/easy/join-two-portions-of-a-path/code.js @@ -1,5 +1,11 @@ function joinPath(portion1, portion2) { - // Your code here. + if (portion1[portion1.length - 1] === "/" && portion2[0] === "/") { + return portion1.substr(0, portion1.length - 1) + portion2; + } else if (portion1[portion1.length - 1] === "/" || portion2[0] === "/") { + return portion1 + portion2; + } else { + return portion1 + "/" + portion2; + } } module.exports = joinPath; From 4cc5d1484f8edfd98ea43205c76750ca59860e96 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 14 Nov 2020 00:25:48 -0800 Subject: [PATCH 054/103] largest swap complete --- easy/largest-swap/code.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/easy/largest-swap/code.js b/easy/largest-swap/code.js index b9443539..55ed7dad 100644 --- a/easy/largest-swap/code.js +++ b/easy/largest-swap/code.js @@ -1,5 +1,11 @@ function largestSwap(num) { - // Your code here. + const oneDigit = num % 10; + const tenDigit = Math.floor(num / 10); + if (oneDigit > tenDigit) { + return false; + } else { + return true; + } } module.exports = largestSwap; From d48c7ddb39522447c9a39170eff78c1fec2ea555 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 15 Nov 2020 01:11:54 -0800 Subject: [PATCH 055/103] pi to decimal complete --- easy/pi-to-n-decimal-places/code.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/easy/pi-to-n-decimal-places/code.js b/easy/pi-to-n-decimal-places/code.js index 56cfb017..cc7b3417 100644 --- a/easy/pi-to-n-decimal-places/code.js +++ b/easy/pi-to-n-decimal-places/code.js @@ -1,5 +1,6 @@ function myPi(n) { - // Your code here. + const pi = 3.141592653589793; + return parseFloat(pi.toFixed(n)); } module.exports = myPi; From a59f1034f7c0a86bd7960ee7eb2a81af8124f708 Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 16 Nov 2020 08:26:54 -0800 Subject: [PATCH 056/103] puzzle piece complete --- easy/puzzle-pieces/code.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/easy/puzzle-pieces/code.js b/easy/puzzle-pieces/code.js index 5014d240..2b793906 100644 --- a/easy/puzzle-pieces/code.js +++ b/easy/puzzle-pieces/code.js @@ -1,5 +1,15 @@ function puzzlePieces(a1, a2) { - // Your code here. + if (a1.length !== a2.length) { + return false; + } + const fit = a1[0] + a2[0]; + for (let i = 1; i < a1.length; i++) { + const currentPiece = a1[i] + a2[i]; + if (fit !== currentPiece) { + return false; + } + } + return true; } module.exports = puzzlePieces; From bbf0bc092d372f8f1278a9d46f848f9efa430647 Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 17 Nov 2020 00:43:41 -0800 Subject: [PATCH 057/103] repeating letter done --- easy/repeating-letters/code.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/easy/repeating-letters/code.js b/easy/repeating-letters/code.js index af356167..685e8f45 100644 --- a/easy/repeating-letters/code.js +++ b/easy/repeating-letters/code.js @@ -1,5 +1,10 @@ function doubleChar(str) { - // Your code here. + let doubleStr = ""; + for (let i = 0; i < str.length; i++) { + doubleStr += str[i]; + doubleStr += str[i]; + } + return doubleStr; } module.exports = doubleChar; From 8b2366a7cb9c137360b0765f16dc29382e40d1b1 Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 18 Nov 2020 09:46:51 -0800 Subject: [PATCH 058/103] factorial complete --- easy/return-the-factorial/code.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/easy/return-the-factorial/code.js b/easy/return-the-factorial/code.js index 0b792944..f50ebe45 100644 --- a/easy/return-the-factorial/code.js +++ b/easy/return-the-factorial/code.js @@ -1,5 +1,9 @@ function factorial(int) { - // Your code here. + let total = 1; + for (let i = 1; i < int; i++) { + total *= i; + } + return total; } module.exports = factorial; From ea914612b026e70f8be7c11c1ffa2d0a3942e304 Mon Sep 17 00:00:00 2001 From: John Ko Date: Thu, 19 Nov 2020 00:11:35 -0800 Subject: [PATCH 059/103] highest and lowest complete --- easy/return-the-highest-and-lowest-numbers/code.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/easy/return-the-highest-and-lowest-numbers/code.js b/easy/return-the-highest-and-lowest-numbers/code.js index 519eb6ef..08a0901d 100644 --- a/easy/return-the-highest-and-lowest-numbers/code.js +++ b/easy/return-the-highest-and-lowest-numbers/code.js @@ -1,5 +1,14 @@ function highLow(str) { - // Your code here. + const numbers = str.split(" ") + let highest = parseInt(numbers[0]) + let lowest = parseInt(numbers[0]) + for (let i = 0; i < numbers.length; i++) { + if (highest < parseInt(numbers[i])) { + highest = parseInt(numbers[i]); + } + if (lowest > parseInt(numbers[i])) lowest = parseInt(numbers[i]) + } + return highest + " " + lowest; } module.exports = highLow; From 3bad750a113407e2f739169902cd8a14b5d22d86 Mon Sep 17 00:00:00 2001 From: John Ko Date: Thu, 19 Nov 2020 23:32:46 -0800 Subject: [PATCH 060/103] attempted secret name --- easy/secret-society/code.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/easy/secret-society/code.js b/easy/secret-society/code.js index 330e7aae..83b1c2c2 100644 --- a/easy/secret-society/code.js +++ b/easy/secret-society/code.js @@ -1,5 +1,9 @@ function societyName(friends) { - // Your code here. + let name = ""; + for (let i = 0; i < friends.length; i++) { + name += friends[i][0]; + } + return name; } module.exports = societyName; From 33e9eade10c96fff682c492a3640e2153674a4ab Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 21 Nov 2020 00:24:30 -0800 Subject: [PATCH 061/103] attempted secret name --- easy/secret-society/code.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/easy/secret-society/code.js b/easy/secret-society/code.js index 83b1c2c2..c4c5826c 100644 --- a/easy/secret-society/code.js +++ b/easy/secret-society/code.js @@ -1,8 +1,15 @@ function societyName(friends) { let name = ""; + const initals = []; for (let i = 0; i < friends.length; i++) { - name += friends[i][0]; + initals.push(friends[i][0]); } + initals.sort(); + + for (let i = 0; i < initals.length; i++) { + name += initals[i] + } + return name; } From 62f3bde660dd2aa60e5abb0538c9d633b450a385 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 22 Nov 2020 00:22:23 -0800 Subject: [PATCH 062/103] snail --- easy/snail-race/code.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/easy/snail-race/code.js b/easy/snail-race/code.js index 6263bcd0..c93121c1 100644 --- a/easy/snail-race/code.js +++ b/easy/snail-race/code.js @@ -1,5 +1,15 @@ function mauriceWins(mSnails, sSnails) { - // Your code here. + let wins = 0; + + if (mSnails[0] > sSnails[2]) { + wins++; + } + if (mSnails[1] > sSnails[0]) { + wins++ + } + if (mSnails[2] > sSnails[1]) { + wins++ + } } module.exports = mauriceWins; From 4d02dab89f262ea51638c210002700889a604902 Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 23 Nov 2020 00:00:08 -0800 Subject: [PATCH 063/103] snail --- easy/snail-race/code.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/easy/snail-race/code.js b/easy/snail-race/code.js index c93121c1..0e9b9acd 100644 --- a/easy/snail-race/code.js +++ b/easy/snail-race/code.js @@ -10,6 +10,12 @@ function mauriceWins(mSnails, sSnails) { if (mSnails[2] > sSnails[1]) { wins++ } + + if (wins >= 2) { + return true; + } else { + return false; + } } module.exports = mauriceWins; From 05699f43161ca8daa277467f7f0a42dee58fcb40 Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 24 Nov 2020 06:44:39 -0800 Subject: [PATCH 064/103] spell complete --- easy/spelling-it-out/code.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/easy/spelling-it-out/code.js b/easy/spelling-it-out/code.js index 796eb731..894a5d6c 100644 --- a/easy/spelling-it-out/code.js +++ b/easy/spelling-it-out/code.js @@ -1,5 +1,8 @@ function spelling(str) { - // Your code here. + const arr = []; + for (let i = 0; i < str.length; i++) { + arr.push(str.substr(0, i)) + } } module.exports = spelling; From f65be588de12d87e1cff43114420376fc2f213bc Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 25 Nov 2020 03:43:01 -0800 Subject: [PATCH 065/103] spell complete --- easy/spelling-it-out/code.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/easy/spelling-it-out/code.js b/easy/spelling-it-out/code.js index 894a5d6c..be22002d 100644 --- a/easy/spelling-it-out/code.js +++ b/easy/spelling-it-out/code.js @@ -3,6 +3,8 @@ function spelling(str) { for (let i = 0; i < str.length; i++) { arr.push(str.substr(0, i)) } + + return arr; } module.exports = spelling; From 571f81cb9497e7eb9b1cfab9f69fa15e0b8f86a0 Mon Sep 17 00:00:00 2001 From: John Ko Date: Thu, 26 Nov 2020 00:03:57 -0800 Subject: [PATCH 066/103] sum of all evens --- easy/sum-of-all-evens-in-a-matrix/code.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/easy/sum-of-all-evens-in-a-matrix/code.js b/easy/sum-of-all-evens-in-a-matrix/code.js index 3055b71f..ae685f44 100644 --- a/easy/sum-of-all-evens-in-a-matrix/code.js +++ b/easy/sum-of-all-evens-in-a-matrix/code.js @@ -1,5 +1,12 @@ function sumOfEvens(arr) { - // Your code here. + let evenTotal = 0; + for (let i = 0; i < arr.length; i++) { + for (let k = 0; k < arr[i].length; k++) { + if (arr[i][k] % 2 === 0) { + evenTotal += arr[i][k]; + } + } + } } module.exports = sumOfEvens; From 5527307216906fa2b1432600a525b2d1665952ff Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 27 Nov 2020 00:02:33 -0800 Subject: [PATCH 067/103] sum of all evens --- easy/sum-of-all-evens-in-a-matrix/code.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/easy/sum-of-all-evens-in-a-matrix/code.js b/easy/sum-of-all-evens-in-a-matrix/code.js index ae685f44..c7df7189 100644 --- a/easy/sum-of-all-evens-in-a-matrix/code.js +++ b/easy/sum-of-all-evens-in-a-matrix/code.js @@ -7,6 +7,8 @@ function sumOfEvens(arr) { } } } + + return evenTotal; } module.exports = sumOfEvens; From 66d8c47549b0b71e891bb619dc5434515b0e16ae Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 28 Nov 2020 06:50:48 -0800 Subject: [PATCH 068/103] sum of cube --- easy/sum-of-cubes/code.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/easy/sum-of-cubes/code.js b/easy/sum-of-cubes/code.js index 0d45b3c9..438fc7fe 100644 --- a/easy/sum-of-cubes/code.js +++ b/easy/sum-of-cubes/code.js @@ -1,5 +1,9 @@ function sumOfCubes(nums) { - // Your code here. + let total = 0; + for (let i = 0; i < nums.length; i++) { + let cube = Math.cube(nums[i]) + total += cube; + } } module.exports = sumOfCubes; From ccc588c6bd232d40b03bd5185387ab9025df1d15 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 29 Nov 2020 06:13:58 -0800 Subject: [PATCH 069/103] sum of cube --- easy/sum-of-cubes/code.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/easy/sum-of-cubes/code.js b/easy/sum-of-cubes/code.js index 438fc7fe..85dbbb88 100644 --- a/easy/sum-of-cubes/code.js +++ b/easy/sum-of-cubes/code.js @@ -4,6 +4,8 @@ function sumOfCubes(nums) { let cube = Math.cube(nums[i]) total += cube; } + + return total; } module.exports = sumOfCubes; From fa95c52bf25388134f9a5375234184010d8e128a Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 30 Nov 2020 07:18:25 -0800 Subject: [PATCH 070/103] transform no dup --- easy/transform-into-an-array-with-no-duplicates/code.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/easy/transform-into-an-array-with-no-duplicates/code.js b/easy/transform-into-an-array-with-no-duplicates/code.js index ff4ab7ca..50d2719f 100644 --- a/easy/transform-into-an-array-with-no-duplicates/code.js +++ b/easy/transform-into-an-array-with-no-duplicates/code.js @@ -1,5 +1,10 @@ function set(arr) { - // Your code here. + const obj = {}; + for (let i = 0; i < arr.length; i++) { + if (!obj.hasOwnProperty(arr[i])) { + obj[arr[i]] = arr[i] + } + } } module.exports = set; From 3259c619fe3ee7ffdaee523b7c63e8e4269a7608 Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 1 Dec 2020 03:48:26 -0800 Subject: [PATCH 071/103] transform no dup --- easy/transform-into-an-array-with-no-duplicates/code.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/easy/transform-into-an-array-with-no-duplicates/code.js b/easy/transform-into-an-array-with-no-duplicates/code.js index 50d2719f..a0365251 100644 --- a/easy/transform-into-an-array-with-no-duplicates/code.js +++ b/easy/transform-into-an-array-with-no-duplicates/code.js @@ -1,10 +1,14 @@ function set(arr) { const obj = {}; + const newArr = []; for (let i = 0; i < arr.length; i++) { if (!obj.hasOwnProperty(arr[i])) { obj[arr[i]] = arr[i] + newArr.push(arr[i]) } } + + return } module.exports = set; From 6af7123b4e7eb8155012adcdb54cd03332a0f2ca Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 2 Dec 2020 00:00:15 -0800 Subject: [PATCH 072/103] transform no dup --- easy/transform-into-an-array-with-no-duplicates/code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/easy/transform-into-an-array-with-no-duplicates/code.js b/easy/transform-into-an-array-with-no-duplicates/code.js index a0365251..538091c7 100644 --- a/easy/transform-into-an-array-with-no-duplicates/code.js +++ b/easy/transform-into-an-array-with-no-duplicates/code.js @@ -8,7 +8,7 @@ function set(arr) { } } - return + return newArr; } module.exports = set; From ccca95514356b549ba5ffac6cb114217a8eaf303 Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 2 Dec 2020 23:57:05 -0800 Subject: [PATCH 073/103] upvote --- easy/transform-upvotes/code.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/easy/transform-upvotes/code.js b/easy/transform-upvotes/code.js index 06cadf92..9613ce8f 100644 --- a/easy/transform-upvotes/code.js +++ b/easy/transform-upvotes/code.js @@ -1,5 +1,6 @@ function transformUpvotes(str) { - // Your code here. + const arr = []; + } module.exports = transformUpvotes; From b6e413e13d052a3cc217a050b352520ec531f9ae Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 2 Dec 2020 23:59:18 -0800 Subject: [PATCH 074/103] upvote --- easy/transform-upvotes/code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/easy/transform-upvotes/code.js b/easy/transform-upvotes/code.js index 9613ce8f..9ec6f0dc 100644 --- a/easy/transform-upvotes/code.js +++ b/easy/transform-upvotes/code.js @@ -1,6 +1,6 @@ function transformUpvotes(str) { const arr = []; - + str.split(" "); } module.exports = transformUpvotes; From e0ad169b194b52f69a026d248773745b53b9fe95 Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 4 Dec 2020 00:01:01 -0800 Subject: [PATCH 075/103] upvote --- easy/transform-upvotes/code.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/easy/transform-upvotes/code.js b/easy/transform-upvotes/code.js index 9ec6f0dc..b9cbdfe1 100644 --- a/easy/transform-upvotes/code.js +++ b/easy/transform-upvotes/code.js @@ -1,6 +1,11 @@ function transformUpvotes(str) { const arr = []; - str.split(" "); + const strArr = str.split(" "); + for(let i = 0; i < strArr.length; i++) { + if (strArr[i].indexOf("k") !== -1) { + + } + } } module.exports = transformUpvotes; From ff0164e4f4819168d4de713fefad9e03d6f0c2af Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 5 Dec 2020 03:14:04 -0800 Subject: [PATCH 076/103] upvote --- easy/transform-upvotes/code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/easy/transform-upvotes/code.js b/easy/transform-upvotes/code.js index b9cbdfe1..6d88cf6f 100644 --- a/easy/transform-upvotes/code.js +++ b/easy/transform-upvotes/code.js @@ -3,7 +3,7 @@ function transformUpvotes(str) { const strArr = str.split(" "); for(let i = 0; i < strArr.length; i++) { if (strArr[i].indexOf("k") !== -1) { - + let newNum = strArr[i].replace(/k/g, ""); } } } From 00c5463fd2e3a520f6add836259b00991b23254f Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 5 Dec 2020 23:59:34 -0800 Subject: [PATCH 077/103] upvote --- easy/transform-upvotes/code.js | 1 + 1 file changed, 1 insertion(+) diff --git a/easy/transform-upvotes/code.js b/easy/transform-upvotes/code.js index 6d88cf6f..2ae69b04 100644 --- a/easy/transform-upvotes/code.js +++ b/easy/transform-upvotes/code.js @@ -4,6 +4,7 @@ function transformUpvotes(str) { for(let i = 0; i < strArr.length; i++) { if (strArr[i].indexOf("k") !== -1) { let newNum = strArr[i].replace(/k/g, ""); + let convertNum = parseInt(newNum); } } } From d94bbac4b1f5b3429280956eb9d2ec88823ac234 Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 7 Dec 2020 00:00:24 -0800 Subject: [PATCH 078/103] upvote --- easy/transform-upvotes/code.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/easy/transform-upvotes/code.js b/easy/transform-upvotes/code.js index 2ae69b04..4275eef0 100644 --- a/easy/transform-upvotes/code.js +++ b/easy/transform-upvotes/code.js @@ -4,7 +4,8 @@ function transformUpvotes(str) { for(let i = 0; i < strArr.length; i++) { if (strArr[i].indexOf("k") !== -1) { let newNum = strArr[i].replace(/k/g, ""); - let convertNum = parseInt(newNum); + let convertNum = parseFloat(newNum); + let trueNumber = convertNum * 1000; } } } From 56dc00fc29262bbccab525b2503f421d6d903ac7 Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 7 Dec 2020 23:47:46 -0800 Subject: [PATCH 079/103] upvote --- easy/transform-upvotes/code.js | 1 + 1 file changed, 1 insertion(+) diff --git a/easy/transform-upvotes/code.js b/easy/transform-upvotes/code.js index 4275eef0..c1e78887 100644 --- a/easy/transform-upvotes/code.js +++ b/easy/transform-upvotes/code.js @@ -6,6 +6,7 @@ function transformUpvotes(str) { let newNum = strArr[i].replace(/k/g, ""); let convertNum = parseFloat(newNum); let trueNumber = convertNum * 1000; + arr.push(trueNumber); } } } From 0877d541bbc4c9d116f36cab1eaef31f79b0fedc Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 8 Dec 2020 23:51:56 -0800 Subject: [PATCH 080/103] upvote --- easy/transform-upvotes/code.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/easy/transform-upvotes/code.js b/easy/transform-upvotes/code.js index c1e78887..73b7bd81 100644 --- a/easy/transform-upvotes/code.js +++ b/easy/transform-upvotes/code.js @@ -9,6 +9,8 @@ function transformUpvotes(str) { arr.push(trueNumber); } } + + return arr; } module.exports = transformUpvotes; From 5989d09e10b70b720f72670a88f7556c7ac93e1c Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 9 Dec 2020 23:53:25 -0800 Subject: [PATCH 081/103] write function --- .../code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js b/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js index 98c363ee..e60b269e 100644 --- a/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js +++ b/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js @@ -1,5 +1,5 @@ function factorial(x) { - // Your code here. + let total = 1; } module.exports = factorial; From be629c47ce7327198ecb716ff30465f7b04bd486 Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 11 Dec 2020 00:05:00 -0800 Subject: [PATCH 082/103] write function --- .../code.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js b/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js index e60b269e..4c99cd96 100644 --- a/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js +++ b/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js @@ -1,5 +1,8 @@ function factorial(x) { let total = 1; + for (let i = 1; i < x; i++) { + + } } module.exports = factorial; From ac7f610418bdb49579e449981cdcb4601fc82ab8 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 12 Dec 2020 00:05:05 -0800 Subject: [PATCH 083/103] write function --- .../code.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js b/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js index 4c99cd96..46458cd3 100644 --- a/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js +++ b/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js @@ -1,7 +1,7 @@ function factorial(x) { let total = 1; - for (let i = 1; i < x; i++) { - + for (let i = 2; i < x; i++) { + total *= i; } } From a4e5485acef9c48ac9c76e26efb317ac6682e233 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 13 Dec 2020 00:00:25 -0800 Subject: [PATCH 084/103] write function --- .../code.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js b/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js index 46458cd3..ba7afb65 100644 --- a/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js +++ b/easy/write-a-function-to-calculate-the-factorial-of-a-number/code.js @@ -3,6 +3,8 @@ function factorial(x) { for (let i = 2; i < x; i++) { total *= i; } + + return total; } module.exports = factorial; From 1f68b98dad56694a67ca50b85c4f594667b44b9a Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 14 Dec 2020 07:10:56 -0800 Subject: [PATCH 085/103] pairs sums --- hard/all-pairs-that-sum-to-target/code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hard/all-pairs-that-sum-to-target/code.js b/hard/all-pairs-that-sum-to-target/code.js index d41667ac..3f5aaa98 100644 --- a/hard/all-pairs-that-sum-to-target/code.js +++ b/hard/all-pairs-that-sum-to-target/code.js @@ -1,5 +1,5 @@ function allPairs(arr, target) { - // Your code here. + const newArr = [] } module.exports = allPairs; From e46b92b3bacb591957b6df68741814adcb3450da Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 14 Dec 2020 23:07:11 -0800 Subject: [PATCH 086/103] pairs sums --- hard/all-pairs-that-sum-to-target/code.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hard/all-pairs-that-sum-to-target/code.js b/hard/all-pairs-that-sum-to-target/code.js index 3f5aaa98..9418af21 100644 --- a/hard/all-pairs-that-sum-to-target/code.js +++ b/hard/all-pairs-that-sum-to-target/code.js @@ -1,5 +1,8 @@ function allPairs(arr, target) { const newArr = [] + for (let i = 0; i < arr.length; i++) { + + } } module.exports = allPairs; From 4152f16c245a636a0196d8454c514b65e13a1415 Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 15 Dec 2020 23:27:44 -0800 Subject: [PATCH 087/103] pairs sums --- hard/all-pairs-that-sum-to-target/code.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hard/all-pairs-that-sum-to-target/code.js b/hard/all-pairs-that-sum-to-target/code.js index 9418af21..da3dfd57 100644 --- a/hard/all-pairs-that-sum-to-target/code.js +++ b/hard/all-pairs-that-sum-to-target/code.js @@ -1,7 +1,9 @@ function allPairs(arr, target) { const newArr = [] for (let i = 0; i < arr.length; i++) { + for (let k = i + 1; k < arr.length; k++) { + } } } From 2c276bb27647c2bf3f52cb289d933198c29e4cc0 Mon Sep 17 00:00:00 2001 From: John Ko Date: Thu, 17 Dec 2020 08:59:25 -0800 Subject: [PATCH 088/103] pairs sums --- hard/all-pairs-that-sum-to-target/code.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hard/all-pairs-that-sum-to-target/code.js b/hard/all-pairs-that-sum-to-target/code.js index da3dfd57..da44f54c 100644 --- a/hard/all-pairs-that-sum-to-target/code.js +++ b/hard/all-pairs-that-sum-to-target/code.js @@ -1,8 +1,10 @@ function allPairs(arr, target) { const newArr = [] - for (let i = 0; i < arr.length; i++) { - for (let k = i + 1; k < arr.length; k++) { + for (let i = 0; i < arr.length - 1; i++) { + for (let k = i + 1; k < arr.length ; k++) { + if (arr[i] + arr[k] === target) { + } } } } From 332bf42fc277f579cf32d2e5b8e3172991114e55 Mon Sep 17 00:00:00 2001 From: John Ko Date: Thu, 17 Dec 2020 23:57:16 -0800 Subject: [PATCH 089/103] pairs sums --- hard/all-pairs-that-sum-to-target/code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hard/all-pairs-that-sum-to-target/code.js b/hard/all-pairs-that-sum-to-target/code.js index da44f54c..8fd88394 100644 --- a/hard/all-pairs-that-sum-to-target/code.js +++ b/hard/all-pairs-that-sum-to-target/code.js @@ -3,7 +3,7 @@ function allPairs(arr, target) { for (let i = 0; i < arr.length - 1; i++) { for (let k = i + 1; k < arr.length ; k++) { if (arr[i] + arr[k] === target) { - + const tempArr = []; } } } From ced3764dd8fefe21790dd004a03988931a64a38c Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 18 Dec 2020 23:58:25 -0800 Subject: [PATCH 090/103] pairs sums --- hard/all-pairs-that-sum-to-target/code.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hard/all-pairs-that-sum-to-target/code.js b/hard/all-pairs-that-sum-to-target/code.js index 8fd88394..5a9b6d7b 100644 --- a/hard/all-pairs-that-sum-to-target/code.js +++ b/hard/all-pairs-that-sum-to-target/code.js @@ -4,6 +4,9 @@ function allPairs(arr, target) { for (let k = i + 1; k < arr.length ; k++) { if (arr[i] + arr[k] === target) { const tempArr = []; + if (arr[i] > arr[k]) { + + } } } } From 702829cedd96816befba43492a77da43f556fd0d Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 19 Dec 2020 23:33:49 -0800 Subject: [PATCH 091/103] pairs sums --- hard/all-pairs-that-sum-to-target/code.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hard/all-pairs-that-sum-to-target/code.js b/hard/all-pairs-that-sum-to-target/code.js index 5a9b6d7b..1ffcd8c6 100644 --- a/hard/all-pairs-that-sum-to-target/code.js +++ b/hard/all-pairs-that-sum-to-target/code.js @@ -5,7 +5,8 @@ function allPairs(arr, target) { if (arr[i] + arr[k] === target) { const tempArr = []; if (arr[i] > arr[k]) { - + arr.push(arr[k]); + arr.push(arr[i]); } } } From e01339e02652ebea855201bd363059c07c5bcf54 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 19 Dec 2020 23:35:08 -0800 Subject: [PATCH 092/103] pairs sums --- hard/all-pairs-that-sum-to-target/code.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hard/all-pairs-that-sum-to-target/code.js b/hard/all-pairs-that-sum-to-target/code.js index 1ffcd8c6..d703a403 100644 --- a/hard/all-pairs-that-sum-to-target/code.js +++ b/hard/all-pairs-that-sum-to-target/code.js @@ -7,6 +7,8 @@ function allPairs(arr, target) { if (arr[i] > arr[k]) { arr.push(arr[k]); arr.push(arr[i]); + } else { + } } } From 21fae2b3c08c7f1e396cd50df5b1e7b6364ee6eb Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 20 Dec 2020 23:44:14 -0800 Subject: [PATCH 093/103] pairs sums --- hard/all-pairs-that-sum-to-target/code.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hard/all-pairs-that-sum-to-target/code.js b/hard/all-pairs-that-sum-to-target/code.js index d703a403..66efa4b5 100644 --- a/hard/all-pairs-that-sum-to-target/code.js +++ b/hard/all-pairs-that-sum-to-target/code.js @@ -8,7 +8,8 @@ function allPairs(arr, target) { arr.push(arr[k]); arr.push(arr[i]); } else { - + arr.push(arr[i]); + arr.push(arr[k]); } } } From a91d558d3f37661f6e968dfd62e0a8a66dbcc81b Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 21 Dec 2020 23:16:00 -0800 Subject: [PATCH 094/103] pairs sums --- hard/all-pairs-that-sum-to-target/code.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hard/all-pairs-that-sum-to-target/code.js b/hard/all-pairs-that-sum-to-target/code.js index 66efa4b5..e691cc2b 100644 --- a/hard/all-pairs-that-sum-to-target/code.js +++ b/hard/all-pairs-that-sum-to-target/code.js @@ -5,12 +5,13 @@ function allPairs(arr, target) { if (arr[i] + arr[k] === target) { const tempArr = []; if (arr[i] > arr[k]) { - arr.push(arr[k]); - arr.push(arr[i]); + tempArr.push(arr[k]); + tempArr.push(arr[i]); } else { - arr.push(arr[i]); - arr.push(arr[k]); + tempArr.push(arr[i]); + tempArr.push(arr[k]); } + newArr.push(tempArr); } } } From 09062b982f4dcb6b9f7735c7a70066241e3905a3 Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 22 Dec 2020 22:20:27 -0800 Subject: [PATCH 095/103] pairs sums --- hard/all-pairs-that-sum-to-target/code.js | 1 + 1 file changed, 1 insertion(+) diff --git a/hard/all-pairs-that-sum-to-target/code.js b/hard/all-pairs-that-sum-to-target/code.js index e691cc2b..6182efc4 100644 --- a/hard/all-pairs-that-sum-to-target/code.js +++ b/hard/all-pairs-that-sum-to-target/code.js @@ -15,6 +15,7 @@ function allPairs(arr, target) { } } } + return newArr; } module.exports = allPairs; From 39e9ec22e28147096079d41334208c7db0aa34ce Mon Sep 17 00:00:00 2001 From: John Ko Date: Wed, 30 Dec 2020 22:34:01 -0800 Subject: [PATCH 096/103] beginning and end pairs --- hard/beginning-and-end-pairs/code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hard/beginning-and-end-pairs/code.js b/hard/beginning-and-end-pairs/code.js index 6dc6139a..2007ddec 100644 --- a/hard/beginning-and-end-pairs/code.js +++ b/hard/beginning-and-end-pairs/code.js @@ -1,5 +1,5 @@ function pairs(arr) { - // Your code here. + const newArr = []; } module.exports = pairs; From 0bc448b879b9b04a90749d20b5a9772ae1e8256b Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 1 Jan 2021 01:08:17 -0800 Subject: [PATCH 097/103] beginning and end pairs --- hard/beginning-and-end-pairs/code.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hard/beginning-and-end-pairs/code.js b/hard/beginning-and-end-pairs/code.js index 2007ddec..523feeaf 100644 --- a/hard/beginning-and-end-pairs/code.js +++ b/hard/beginning-and-end-pairs/code.js @@ -1,5 +1,11 @@ function pairs(arr) { const newArr = []; + let arrHalf = null; + if (arr.length % 2 === 0) { + arrHalf = arr.length / 2; + } else { + arrHalf = (arr.length - 1) / 2; + } } module.exports = pairs; From f5d8f477d98ff33316cf6c9f002ed6463589ff36 Mon Sep 17 00:00:00 2001 From: John Ko Date: Fri, 1 Jan 2021 23:52:50 -0800 Subject: [PATCH 098/103] beginning and end pairs --- hard/beginning-and-end-pairs/code.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hard/beginning-and-end-pairs/code.js b/hard/beginning-and-end-pairs/code.js index 523feeaf..81541030 100644 --- a/hard/beginning-and-end-pairs/code.js +++ b/hard/beginning-and-end-pairs/code.js @@ -6,6 +6,10 @@ function pairs(arr) { } else { arrHalf = (arr.length - 1) / 2; } + + for (let i = 0; i < arrHalf; i++) { + + } } module.exports = pairs; From 2f76a72e0f755ccf36434d1ff9e9ca8e2f3afe45 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 2 Jan 2021 23:51:32 -0800 Subject: [PATCH 099/103] beginning and end pairs --- hard/beginning-and-end-pairs/code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hard/beginning-and-end-pairs/code.js b/hard/beginning-and-end-pairs/code.js index 81541030..8e79979a 100644 --- a/hard/beginning-and-end-pairs/code.js +++ b/hard/beginning-and-end-pairs/code.js @@ -8,7 +8,7 @@ function pairs(arr) { } for (let i = 0; i < arrHalf; i++) { - + const tempArr = []; } } From 97e78ccf4acc0f38b46c8efac1f32b9b67e0fe78 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sat, 2 Jan 2021 23:53:10 -0800 Subject: [PATCH 100/103] beginning and end pairs --- hard/beginning-and-end-pairs/code.js | 1 + 1 file changed, 1 insertion(+) diff --git a/hard/beginning-and-end-pairs/code.js b/hard/beginning-and-end-pairs/code.js index 8e79979a..095a18e3 100644 --- a/hard/beginning-and-end-pairs/code.js +++ b/hard/beginning-and-end-pairs/code.js @@ -9,6 +9,7 @@ function pairs(arr) { for (let i = 0; i < arrHalf; i++) { const tempArr = []; + tempArr.push(arr[i]); } } From 250ec307dbc66fa55efd0b06f7019b4c36f1bbc4 Mon Sep 17 00:00:00 2001 From: John Ko Date: Sun, 3 Jan 2021 22:24:55 -0800 Subject: [PATCH 101/103] beginning and end pairs --- hard/beginning-and-end-pairs/code.js | 1 + 1 file changed, 1 insertion(+) diff --git a/hard/beginning-and-end-pairs/code.js b/hard/beginning-and-end-pairs/code.js index 095a18e3..01220dd2 100644 --- a/hard/beginning-and-end-pairs/code.js +++ b/hard/beginning-and-end-pairs/code.js @@ -10,6 +10,7 @@ function pairs(arr) { for (let i = 0; i < arrHalf; i++) { const tempArr = []; tempArr.push(arr[i]); + tempArr.push(arr[arr.length - (i + 1)]) } } From ddcb410749fc18a10f6bae388f7d6ade6918e136 Mon Sep 17 00:00:00 2001 From: John Ko Date: Mon, 4 Jan 2021 22:03:45 -0800 Subject: [PATCH 102/103] beginning and end pairs --- hard/beginning-and-end-pairs/code.js | 1 + 1 file changed, 1 insertion(+) diff --git a/hard/beginning-and-end-pairs/code.js b/hard/beginning-and-end-pairs/code.js index 01220dd2..da1b083f 100644 --- a/hard/beginning-and-end-pairs/code.js +++ b/hard/beginning-and-end-pairs/code.js @@ -12,6 +12,7 @@ function pairs(arr) { tempArr.push(arr[i]); tempArr.push(arr[arr.length - (i + 1)]) } + newArr.push(tempArr); } module.exports = pairs; From 45ccd20310f0fe19c4a63f0cae98f3dacce385c0 Mon Sep 17 00:00:00 2001 From: John Ko Date: Tue, 5 Jan 2021 22:32:14 -0800 Subject: [PATCH 103/103] beginning and end pairs --- hard/beginning-and-end-pairs/code.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hard/beginning-and-end-pairs/code.js b/hard/beginning-and-end-pairs/code.js index da1b083f..e1e15779 100644 --- a/hard/beginning-and-end-pairs/code.js +++ b/hard/beginning-and-end-pairs/code.js @@ -11,8 +11,11 @@ function pairs(arr) { const tempArr = []; tempArr.push(arr[i]); tempArr.push(arr[arr.length - (i + 1)]) + newArr.push(tempArr); } - newArr.push(tempArr); + return newArr; } + + module.exports = pairs;