From c013f56c643132bdbcc70ef3a847577c1a7d217c Mon Sep 17 00:00:00 2001 From: Leah Ann Mitchell Date: Fri, 28 Apr 2017 12:25:27 -0700 Subject: [PATCH 1/6] complete makechange challenge --- src/comment from make_change.js | 87 +++++++++++++++++++++++++++++++++ src/makeChange.js | 53 +++++++++++++++++++- 2 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/comment from make_change.js diff --git a/src/comment from make_change.js b/src/comment from make_change.js new file mode 100644 index 0000000..d3a5028 --- /dev/null +++ b/src/comment from make_change.js @@ -0,0 +1,87 @@ +/*const useQaurter = function(amountGiven, price) { + amountGiven = amountGiven - 25 + coins.qaurters++ + return amountGiven + + //console.log(amountGiven) + } + + + + + const useDime = function(amountGiven, price) { + amountGiven = amountGiven - 10 + coins.dimes++ + return amountGiven + + //console.log(amountGiven) + } + + + + const useNickel = function(amountGiven, price) { + amountGiven = amountGiven - 5 + coins.nickels++ + return amountGiven + + //console.log(amountGiven) + } + + + + const usePenny = function(amountGiven, price) { + amountGiven = amountGiven - 1 + coins.pennies++ + return amountGiven + + //console.log(amountGiven) + } + + function makeChange({price, amountGiven}) { + let results = {} + if(price === amountGiven) { + + results.quarters = coins.quarters + results.dimes = coins.dimes + results.nickels = coins.nickels + results.pennies = coins.pennies + + coins.quarters = 0 + coins.dimes = 0 + coins.nickels = 0 + coins.pennies = 0 + + + } + + if( difference >= 25 ) { + amountGiven = takeQuarter(amountGiven, coins) + return makeChange({price: price, amountGiven: amountGiven}) + }else if( difference >= 10) { + amountGiven = takeDime(amountGiven, price) + return makeChange({price: price, amountGiven: amountGiven}) + }else if(difference >= 5){ + amountGiven = takeNickel(amountGiven, price) + return makeChange({price: price, amountGiven: amountGiven}) + }else if(difference >= 1){ + amountGiven = takePenny(amountGiven, price) + return makeChange({price: price, amountGiven: amountGiven}) + } + } +this worked + +function makeChange({price, amountGiven}) { + + const coins = { + // quarters: 0, + // dimes: 0, + // nickels: 0, + pennies: 0, + } + + let difference = amountGiven - price + + coins.pennies = difference + return coins + +} \ No newline at end of file diff --git a/src/makeChange.js b/src/makeChange.js index 59d89b1..05b1da0 100644 --- a/src/makeChange.js +++ b/src/makeChange.js @@ -1,3 +1,54 @@ +const coins = { + quarters: 0, + dimes: 0, + nickels: 0, + pennies: 0 +} +const takeQuarter = function(amountGiven, price){ + amountGiven = amountGiven - 25 + coins.quarters++ + return amountGiven +} +const takeDime = function(amountGiven, price){ + amountGiven = amountGiven - 10 + coins.dimes++ + return amountGiven +} +const takeNickel = function(amountGiven, price){ + amountGiven = amountGiven - 5 + coins.nickels++ + return amountGiven +} +const takePenny = function(amountGiven, price){ + amountGiven = amountGiven - 1 + coins.pennies++ + return amountGiven +} export default function makeChange({price, amountGiven}) { - // your code here + let results = {} + if(price === amountGiven) { + results.quarters = coins.quarters + results.dimes = coins.dimes + results.nickels = coins.nickels + results.pennies = coins.pennies + + coins.quarters = 0 + coins.dimes = 0 + coins.nickels = 0 + coins.pennies = 0 + return results + } + if(amountGiven - price >= 25){ + amountGiven = takeQuarter(amountGiven, coins) + return makeChange({price: price, amountGiven: amountGiven}) + }else if(amountGiven - price >= 10){ + amountGiven = takeDime(amountGiven, price) + return makeChange({price: price, amountGiven: amountGiven}) + }else if(amountGiven - price >= 5){ + amountGiven = takeNickel(amountGiven, price) + return makeChange({price: price, amountGiven: amountGiven}) + }else if(amountGiven - price >= 1){ + amountGiven = takePenny(amountGiven, price) + return makeChange({price: price, amountGiven: amountGiven}) + } } From 9bad0aacc39ce2b6aed961e21a61d032daaa4a39 Mon Sep 17 00:00:00 2001 From: Leah Ann Mitchell Date: Fri, 28 Apr 2017 12:39:25 -0700 Subject: [PATCH 2/6] Solution and test --- src/collatzConjection,js | 0 src/collatzConjection.js | 17 ++++++++++++++ src/collatzConjecture.js | 17 ++++++++++++++ src/comment from make_change.js | 41 +++++++++++++++++++++++++++++++++ test/collatzConjection_test.js | 15 ++++++++++++ test/collatzConjecture_test.js | 15 ++++++++++++ 6 files changed, 105 insertions(+) create mode 100644 src/collatzConjection,js create mode 100644 src/collatzConjection.js create mode 100644 src/collatzConjecture.js create mode 100644 test/collatzConjection_test.js create mode 100644 test/collatzConjecture_test.js diff --git a/src/collatzConjection,js b/src/collatzConjection,js new file mode 100644 index 0000000..e69de29 diff --git a/src/collatzConjection.js b/src/collatzConjection.js new file mode 100644 index 0000000..e8e281e --- /dev/null +++ b/src/collatzConjection.js @@ -0,0 +1,17 @@ + +let arr = [] +export default function collatzConjecture(num){ + if(num === 1){ + arr.push(1) + return arr + } + if(num % 2 === 0){ + arr.push(num) + num = num / 2 + return collatzConjecture(num) + }else if(num % 2 !== 0){ + arr.push(num) + num = num * 3 + 1 + return collatzConjecture(num) + } +} \ No newline at end of file diff --git a/src/collatzConjecture.js b/src/collatzConjecture.js new file mode 100644 index 0000000..e8e281e --- /dev/null +++ b/src/collatzConjecture.js @@ -0,0 +1,17 @@ + +let arr = [] +export default function collatzConjecture(num){ + if(num === 1){ + arr.push(1) + return arr + } + if(num % 2 === 0){ + arr.push(num) + num = num / 2 + return collatzConjecture(num) + }else if(num % 2 !== 0){ + arr.push(num) + num = num * 3 + 1 + return collatzConjecture(num) + } +} \ No newline at end of file diff --git a/src/comment from make_change.js b/src/comment from make_change.js index d3a5028..4a20eaa 100644 --- a/src/comment from make_change.js +++ b/src/comment from make_change.js @@ -84,4 +84,45 @@ function makeChange({price, amountGiven}) { coins.pennies = difference return coins +} + +export default function makeChange({price, amountGiven}) { + + const coins = { + quarters: 0, + dimes: 0, + nickels: 0, + pennies: 0, + } + + let difference = amountGiven - price + + let quarterValue = 25, + let dimeValue = 10, + let pennyValue = 1, + let nickelValue = 5, + + + let numberOfNickels = Math.floor(difference / nickelValue ) +let numberOfPennies = Math.floor(difference / pennyValue ) +let numberOfDimes = Math.floor(difference / dimeValue ) +let numberOfQuarters = Math.floor(difference / quarterValue ) + + + + let numberOfPennies = difference + let numberOfNickels = difference + let numberOfDimes = difference + let numberOfQuarters = difference + + + coins.nickels = numberOfNickels + coins.pennies = numberOfPennies + coins.dimes = numberOfDimes + coins.quarters = numberOfQuarters + + + + return coins + } \ No newline at end of file diff --git a/test/collatzConjection_test.js b/test/collatzConjection_test.js new file mode 100644 index 0000000..839c4b2 --- /dev/null +++ b/test/collatzConjection_test.js @@ -0,0 +1,15 @@ +import { expect } from 'chai' +import collatzConjecture from '../src/collatzConjecture' + +describe('collatzConjecture()', function(){ + + it('should be a function', function(){ + expect(collatzConjecture).to.be.a('function') + }) + + it('take a number a perform an evaluation based on what the current number is then returns an array', function(){ + expect(collatzConjecture(7)).to.eql([7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]) + expect(collatzConjecture(12)).to.eql([ 7,22,11,34,17,52,26,13,40,20,10, + 5,16,8,4,2,1,12,6,3,10,5,16,8,4,2,1]) + }) +}) diff --git a/test/collatzConjecture_test.js b/test/collatzConjecture_test.js new file mode 100644 index 0000000..839c4b2 --- /dev/null +++ b/test/collatzConjecture_test.js @@ -0,0 +1,15 @@ +import { expect } from 'chai' +import collatzConjecture from '../src/collatzConjecture' + +describe('collatzConjecture()', function(){ + + it('should be a function', function(){ + expect(collatzConjecture).to.be.a('function') + }) + + it('take a number a perform an evaluation based on what the current number is then returns an array', function(){ + expect(collatzConjecture(7)).to.eql([7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]) + expect(collatzConjecture(12)).to.eql([ 7,22,11,34,17,52,26,13,40,20,10, + 5,16,8,4,2,1,12,6,3,10,5,16,8,4,2,1]) + }) +}) From c96d2d78656c56fbbe79f70678ed00df7c3f2980 Mon Sep 17 00:00:00 2001 From: Leah Ann Mitchell Date: Fri, 28 Apr 2017 12:45:41 -0700 Subject: [PATCH 3/6] Complete solution and test --- src/factorial.js | 7 +++++++ test/factorial_test.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/factorial.js create mode 100644 test/factorial_test.js diff --git a/src/factorial.js b/src/factorial.js new file mode 100644 index 0000000..2656392 --- /dev/null +++ b/src/factorial.js @@ -0,0 +1,7 @@ +export default function factorial(num){ + let total = 1 + for (var i = 1; i <= num; i++) { + total === total * i + } + return total +} diff --git a/test/factorial_test.js b/test/factorial_test.js new file mode 100644 index 0000000..bce6528 --- /dev/null +++ b/test/factorial_test.js @@ -0,0 +1,16 @@ +import { expect } from 'chai' +import factorial from '../src/factorial' + +describe('factorial()', function(){ + + it('should be a function', function(){ + expect(factorial).to.be.a('function') + }) + + it('takes a number then returns the factorial of that number',function(){ + expect(factorial(5)).to.eql(120) + expect(factorial(10)).to.eql(3628800) + expect(factorial(20)).to.eql(2432902008176640000) + }) + +}) \ No newline at end of file From 139dcc294038d1077bfbbf4402aad9baff9ada4a Mon Sep 17 00:00:00 2001 From: Leah Ann Mitchell Date: Fri, 28 Apr 2017 12:53:22 -0700 Subject: [PATCH 4/6] complete solution and test --- src/factorial.js | 2 +- src/fibonacci.js | 9 +++++++++ test/collatzConjection_test.js | 15 --------------- test/fibonacci_test.js | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 src/fibonacci.js delete mode 100644 test/collatzConjection_test.js create mode 100644 test/fibonacci_test.js diff --git a/src/factorial.js b/src/factorial.js index 2656392..9e0ed7f 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,7 +1,7 @@ export default function factorial(num){ let total = 1 for (var i = 1; i <= num; i++) { - total === total * i + total = total * i } return total } diff --git a/src/fibonacci.js b/src/fibonacci.js new file mode 100644 index 0000000..94c1fb9 --- /dev/null +++ b/src/fibonacci.js @@ -0,0 +1,9 @@ +export default function fibonacci(num){ + let fib = [] + fib[0] = 0 + fib[1] = 1 + for(let i = 2; i < num; i++){ + fib[i] = fib[i - 2] + fib[i - 1] + } + return fib +} \ No newline at end of file diff --git a/test/collatzConjection_test.js b/test/collatzConjection_test.js deleted file mode 100644 index 839c4b2..0000000 --- a/test/collatzConjection_test.js +++ /dev/null @@ -1,15 +0,0 @@ -import { expect } from 'chai' -import collatzConjecture from '../src/collatzConjecture' - -describe('collatzConjecture()', function(){ - - it('should be a function', function(){ - expect(collatzConjecture).to.be.a('function') - }) - - it('take a number a perform an evaluation based on what the current number is then returns an array', function(){ - expect(collatzConjecture(7)).to.eql([7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]) - expect(collatzConjecture(12)).to.eql([ 7,22,11,34,17,52,26,13,40,20,10, - 5,16,8,4,2,1,12,6,3,10,5,16,8,4,2,1]) - }) -}) diff --git a/test/fibonacci_test.js b/test/fibonacci_test.js new file mode 100644 index 0000000..5807e3d --- /dev/null +++ b/test/fibonacci_test.js @@ -0,0 +1,16 @@ +import { expect } from 'chai' +import fibonacci from '../src/fibonacci' + +describe('fibonacci()', function(){ + + it('should be a function', function(){ + expect(fibonacci).to.be.a('function') + }) + + it('receives a number and constructs a fibonacci sequence until it reaches that number', function() { + expect(fibonacci(10)).to.eql([0, 1, 1, 2, 3, 5, 8, 13, 21, 34]) + expect(fibonacci(16)).to.eql([0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]) + }) + +}) + From b6a0ea954b3665954f05b3e4e4e94f4c831065be Mon Sep 17 00:00:00 2001 From: Leah Ann Mitchell Date: Fri, 28 Apr 2017 12:57:41 -0700 Subject: [PATCH 5/6] make test and complete solution --- src/collatzConjection,js | 0 src/collatzConjection.js | 17 ----------------- src/fizzBuzz.js | 12 ++++++++++++ test/fizzBuzz_test.js | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 17 deletions(-) delete mode 100644 src/collatzConjection,js delete mode 100644 src/collatzConjection.js create mode 100644 src/fizzBuzz.js create mode 100644 test/fizzBuzz_test.js diff --git a/src/collatzConjection,js b/src/collatzConjection,js deleted file mode 100644 index e69de29..0000000 diff --git a/src/collatzConjection.js b/src/collatzConjection.js deleted file mode 100644 index e8e281e..0000000 --- a/src/collatzConjection.js +++ /dev/null @@ -1,17 +0,0 @@ - -let arr = [] -export default function collatzConjecture(num){ - if(num === 1){ - arr.push(1) - return arr - } - if(num % 2 === 0){ - arr.push(num) - num = num / 2 - return collatzConjecture(num) - }else if(num % 2 !== 0){ - arr.push(num) - num = num * 3 + 1 - return collatzConjecture(num) - } -} \ No newline at end of file diff --git a/src/fizzBuzz.js b/src/fizzBuzz.js new file mode 100644 index 0000000..9f438c4 --- /dev/null +++ b/src/fizzBuzz.js @@ -0,0 +1,12 @@ +export default function fizzBuzz(arr){ + for(let num in arr){ + if(arr[num] % 3 === 0 && arr[num] % 5 == 0){ + arr.splice(num, 1, 'FizzBuzz') + }else if(arr[num] % 3 === 0){ + arr.splice(num, 1, 'Fizz') + }else if(arr[num] % 5 === 0){ + arr.splice(num,1,'Buzz') + } + } + return arr +} \ No newline at end of file diff --git a/test/fizzBuzz_test.js b/test/fizzBuzz_test.js new file mode 100644 index 0000000..d4bc29e --- /dev/null +++ b/test/fizzBuzz_test.js @@ -0,0 +1,19 @@ +import { expect } from 'chai' +import fizzBuzz from '../src/fizzBuzz' + +describe('fizzBuzz()', function(){ + + it('should be a function', function(){ + expect(fizzBuzz).to.be.a('function') + }) + + it('take an array of numbers and replace multiples of 3 with \'Fizz\' and multiples of 5 are replaced with \'Buzz\'', function(){ + let arr = [] + for(let i = 1; i < 101; i++){ + arr.push(i) + } + expect(fizzBuzz(arr)[14]).to.eql('FizzBuzz') + expect(fizzBuzz(arr)[29]).to.eql('FizzBuzz') + expect(fizzBuzz(arr)[32]).to.eql('Fizz') + }) +}) \ No newline at end of file From 36acda39039ecb81853792fcd658c84af09aad4d Mon Sep 17 00:00:00 2001 From: Leah Ann Mitchell Date: Fri, 28 Apr 2017 13:03:57 -0700 Subject: [PATCH 6/6] make test and complete solution --- src/palindrome.js | 8 ++++++++ test/palindrome_test.js | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/palindrome.js create mode 100644 test/palindrome_test.js diff --git a/src/palindrome.js b/src/palindrome.js new file mode 100644 index 0000000..9360d61 --- /dev/null +++ b/src/palindrome.js @@ -0,0 +1,8 @@ +export default function isPalindrome(str){ + let reversedStr = str + reversedStr = reversedStr.replace(/[^a-zA-z]/g, '') + reversedStr = reversedStr.toLowerCase().split('').reverse().join('') + str = str.replace(/[^a-zA-Z]/g, '') + str = str.toLowerCase() + return str === reversedStr +} \ No newline at end of file diff --git a/test/palindrome_test.js b/test/palindrome_test.js new file mode 100644 index 0000000..ed53307 --- /dev/null +++ b/test/palindrome_test.js @@ -0,0 +1,16 @@ +import { expect } from 'chai' +import isPalindrome from '../src/palindrome' + +describe('isPalindrome()', function(){ + + it('should be a function', function(){ + expect(isPalindrome).to.be.a('function') + }) + + it('Determine if a string is a palindrome. Return true or false.', function(){ + expect(isPalindrome('radar')).to.be.true + expect(isPalindrome('A man, a plan, a canal: Panama')).to.be.true + expect(isPalindrome('bananas')).to.be.false + }) + +}) \ No newline at end of file