From 6643b612f34d8d8244099341f7bfa42d2504345f Mon Sep 17 00:00:00 2001 From: afterthebleep Date: Tue, 21 Mar 2017 19:56:29 -0700 Subject: [PATCH 01/11] completed challenges 1-3 --- README.md | 2 +- src/fizzBuzz.js | 15 +++++++++++++++ src/isPalindrome.js | 12 ++++++++++++ src/makeChange.js | 17 ++++++++++++++++- 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/fizzBuzz.js create mode 100644 src/isPalindrome.js diff --git a/README.md b/README.md index 783e9c5..2daf9dc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Core Algorithms +# Core Algorithms #teamName premium-partridge #Aisha Ortiz and Thomas Dunn Tests and implementations for algorithms commonly used in job interviews. See the full list in the [algorithms.md](algorithms.md) file. diff --git a/src/fizzBuzz.js b/src/fizzBuzz.js new file mode 100644 index 0000000..6476a08 --- /dev/null +++ b/src/fizzBuzz.js @@ -0,0 +1,15 @@ +let list = new Array(100); + + for (let i = 0; i < 100; i++) { + list[i] = i + 1; // $$c populates the array. +1 is necessary because arrays are 0 index based and you want to store 1 - 100 in it, NOT 0-99.{ + + //list[i] is equal to an index in the array + if (list[i] % 5 === 0 && list[i] % 3 === 0) { // populate multiples of both five && three with "FIZZBUZZ" + list[i] = "FizzBuzz" + } else if (list[i] % 5 === 0) { // populate multiples of five with "BUZZ" + list[i] = "Buzz" + } else if (list[i] % 3 === 0) { // populate multiples of three with "FIZZ" + list[i] = "Fizz" + } + } +console.log(list); diff --git a/src/isPalindrome.js b/src/isPalindrome.js new file mode 100644 index 0000000..68f8e93 --- /dev/null +++ b/src/isPalindrome.js @@ -0,0 +1,12 @@ +function isPalindrome(str) { + var regString = str.toLowerCase().replace(/[^0-9a-z]/gi, '').split(''); + + for (var i = 0; i < regString.length/2; i++) { + if (regString[i] !== regString[regString.length -1 -i]) { + return false; + } + } + return true; +} + +console.log(); diff --git a/src/makeChange.js b/src/makeChange.js index 59d89b1..ac76168 100644 --- a/src/makeChange.js +++ b/src/makeChange.js @@ -1,3 +1,18 @@ export default function makeChange({price, amountGiven}) { - // your code here + // your code here +let coins = {quarters: 25, dimes: 10, nickels: 5, pennies: 1 } +let changeDue = amountGiven - price + + for(let key in coins) { + let numberOfCoins = Math.floor(changeDue / coins[key]) + /*takes the changeDue divides it by coin section of quarters (25) resulting in a + decimal of 1.64, then Math.floor round down to the nearest integer which is + 1 (<= the given number) and assigns it to the variable numberOfCoins. + */ + changeDue -= coins[keys] * numberOfCoins + + coins[key] = numberOfCoins + + } + return coins; } From 3eb1bdfafa69ee33f14e887ecc047855d75e58eb Mon Sep 17 00:00:00 2001 From: aisha 'ai' ortiz Date: Wed, 22 Mar 2017 09:40:14 -0700 Subject: [PATCH 02/11] Delete isPalindrome.js --- src/isPalindrome.js | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 src/isPalindrome.js diff --git a/src/isPalindrome.js b/src/isPalindrome.js deleted file mode 100644 index 68f8e93..0000000 --- a/src/isPalindrome.js +++ /dev/null @@ -1,12 +0,0 @@ -function isPalindrome(str) { - var regString = str.toLowerCase().replace(/[^0-9a-z]/gi, '').split(''); - - for (var i = 0; i < regString.length/2; i++) { - if (regString[i] !== regString[regString.length -1 -i]) { - return false; - } - } - return true; -} - -console.log(); From 358d6eb03c3e3112d4d400782a0d06756a2486a4 Mon Sep 17 00:00:00 2001 From: afterthebleep Date: Thu, 23 Mar 2017 13:57:40 -0700 Subject: [PATCH 03/11] completed makeCHanges exercise. all test passing. --- src/makeChange.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/makeChange.js b/src/makeChange.js index 59d89b1..ac76168 100644 --- a/src/makeChange.js +++ b/src/makeChange.js @@ -1,3 +1,18 @@ export default function makeChange({price, amountGiven}) { - // your code here + // your code here +let coins = {quarters: 25, dimes: 10, nickels: 5, pennies: 1 } +let changeDue = amountGiven - price + + for(let key in coins) { + let numberOfCoins = Math.floor(changeDue / coins[key]) + /*takes the changeDue divides it by coin section of quarters (25) resulting in a + decimal of 1.64, then Math.floor round down to the nearest integer which is + 1 (<= the given number) and assigns it to the variable numberOfCoins. + */ + changeDue -= coins[keys] * numberOfCoins + + coins[key] = numberOfCoins + + } + return coins; } From d47c1ea379167c8b4376c1241ff3799c8ce983fb Mon Sep 17 00:00:00 2001 From: afterthebleep Date: Thu, 23 Mar 2017 14:10:24 -0700 Subject: [PATCH 04/11] completed fizzBuzz exercise. all test passing --- src/fizzBuzz.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/fizzBuzz.js diff --git a/src/fizzBuzz.js b/src/fizzBuzz.js new file mode 100644 index 0000000..0e820cb --- /dev/null +++ b/src/fizzBuzz.js @@ -0,0 +1,14 @@ +let list = new Array(100); + + for (let i = 0; i < 100; i++) { + list[i] = i + 1; // $$c populates the array. +1 is necessary because arrays are 0 index based and you want to store 1 - 100 in it, NOT 0-99.{ + + //list[i] is equal to an index in the array + if (list[i] % 5 === 0 && list[i] % 3 === 0) { // populate multiples of both five && three with "FIZZBUZZ" + list[i] = "FizzBuzz" + } else if (list[i] % 5 === 0) { // populate multiples of five with "BUZZ" + list[i] = "Buzz" + } else if (list[i] % 3 === 0) { // populate multiples of three with "FIZZ" + list[i] = "Fizz" + } + } From 967f3b647f8961b24bcfaaf2fa2fd2768b342ddf Mon Sep 17 00:00:00 2001 From: afterthebleep Date: Thu, 23 Mar 2017 14:20:14 -0700 Subject: [PATCH 05/11] completed isPalindrome. all tests passing. --- src/isPalindrome.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/isPalindrome.js diff --git a/src/isPalindrome.js b/src/isPalindrome.js new file mode 100644 index 0000000..9cd205e --- /dev/null +++ b/src/isPalindrome.js @@ -0,0 +1,23 @@ + +function isPalindrome(str) { + + str = str.replace(/[^0-9a-z]/gi, "").toLowerCase(); + let palindrome = str.split("").reverse().join(""); + if (str === palindrome) { + return true; + } else { + return false; + } +} + +/*console.log( + + isPalindrome('radar') + => true + + isPalindrome('bananas') + => false + + isPalindrome('A man, a plan, a canal: Panama') + => true + isPalindrome("A man, a plan, a canal: Panama")); */ From e99480a1dffe10f25d683237b5399c74f9adadf3 Mon Sep 17 00:00:00 2001 From: tdunn1248 Date: Thu, 23 Mar 2017 14:45:30 -0700 Subject: [PATCH 06/11] completed fibonacci sequence. all test passsed --- src/fibonacci.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/fibonacci.js diff --git a/src/fibonacci.js b/src/fibonacci.js new file mode 100644 index 0000000..e69de29 From ad223fff9e039037353b6a05a0fda416bc891c2d Mon Sep 17 00:00:00 2001 From: tdunn1248 Date: Thu, 23 Mar 2017 16:46:56 -0700 Subject: [PATCH 07/11] adds testing --- algorithmTest1Week3.html | 10 ++++++++++ core-algorithms | 1 + src/fibonacci.js | 15 +++++++++++++++ src/isPalindrome.js | 14 ++++++++++++++ test/fizzBuzzTests.js | 0 test/isPalindrome_test.js | 20 ++++++++++++++++++++ 6 files changed, 60 insertions(+) create mode 100644 algorithmTest1Week3.html create mode 160000 core-algorithms create mode 100644 src/fibonacci.js create mode 100644 src/isPalindrome.js create mode 100644 test/fizzBuzzTests.js create mode 100644 test/isPalindrome_test.js diff --git a/algorithmTest1Week3.html b/algorithmTest1Week3.html new file mode 100644 index 0000000..2d1d662 --- /dev/null +++ b/algorithmTest1Week3.html @@ -0,0 +1,10 @@ + + + + + + + +