From 61636fcf54587c5ee9cf8a8488aecf7614a3360a Mon Sep 17 00:00:00 2001 From: SomayaB Date: Mon, 24 Apr 2017 13:41:04 -0700 Subject: [PATCH 01/20] Update README and add CONTRACT file --- CONTRACT.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 5 ++++ 2 files changed, 74 insertions(+) create mode 100644 CONTRACT.md diff --git a/CONTRACT.md b/CONTRACT.md new file mode 100644 index 0000000..3d3b54d --- /dev/null +++ b/CONTRACT.md @@ -0,0 +1,69 @@ +#158 Core Algorithms [Classic, Numeric, and Set] +#filthy-gerbil +Somaya Bounouar +http://jsdev.learnersguild.org/goals/158-Core_Algorithms-Classic_Numeric_and_Set.html + + +# Core Algorithms [Classic, Numeric, and Set] + +## Challenge Rating + +This goal will likely be within your ZPD if you... + +- Can write programs and tests using Node.js and npm +- Can use problem decomposition to split difficult problems into smaller parts +- Have used pseudocode as an intermediary step in writing a program +- Are interested in common computer science algorithms +- Are interested in critical thinking and problem solving + +## Description + +This is a sub-goal of [Core Algorithms][core-algos]. Reference that goal for more description, context, and resources. + +Complete **ONLY** the [Classic](https://github.com/GuildCrafts/core-algorithms/blob/master/algorithms.md#classic), [Numeric](https://github.com/GuildCrafts/core-algorithms/blob/master/algorithms.md#numeric), and [Set Operations](https://github.com/GuildCrafts/core-algorithms/blob/master/algorithms.md#set-operations) algorithms, not the Sorting/Searching or Graphing/Geometry. That's a [separate goal][core-algos-adv]. :) + +## Specifications + +- [ ] Artifact produced is a fork of the [core-algorithms][core-algorithms] repo. +- [ ] Can run all tests with `npm test`. +- [ ] `makeChange()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [ ] Tests for `makeChange()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [ ] `fizzBuzz()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [ ] Tests for `fizzBuzz()` exist. +- [ ] `isPalindrome()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [ ] Tests for `isPalindrome()` exist with at least 2 unit tests using valid inputs. +- [ ] `factorial()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [ ] Tests for `factorial()` exist with at least 2 unit tests using valid inputs. +- [ ] `fibonacci()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [ ] Tests for `fibonacci()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [ ] `collatzConjecture()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [ ] Tests for `collatzConjecture()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [ ] `setUnion()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [ ] Tests for `setUnion()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [ ] `setIntersection()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [ ] Tests for `setIntersection()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [ ] `setComplement()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [ ] Tests for `setComplement()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [ ] `setSymmetricDifference()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [ ] Tests for `setSymmetricDifference()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [ ] Repository includes a README file with basic installation and setup instructions. +- [ ] All dependencies are properly declared in `package.json`. +- [ ] All major features are added via pull requests with a clear description and concise commit messages. +- [ ] Code uses a linter and there are no linting errors. +- [ ] Variables, functions, files, etc. have appropriate and meaningful names. +- [ ] Functions are small and serve a single purpose. +- [ ] The artifact produced is properly licensed, preferably with the [MIT license][mit-license]. + +### Stretch + +Pick a _different_ programming language from JavaScript (e.g. Ruby, Swift, Python, C, Java...) and write tests & implementations for each. + +- [ ] Can run all non-JavaScript tests with a single command. +- [ ] For each algorithm identified above, there exists: + - [ ] a test file with multiple unit tests for each algorithm _in a language other than JavaScript_. + - [ ] an implementation file with a correct implementation of the algorithm _in a language other than JavaScript_. + + +[core-algos]: {{ site.url }}{% link _goals/123-Core_Algorithms.md %} +[core-algos-adv]: {{ site.url }}{% link _goals/159-Core_Algorithms-Sorting_Searching_Graphing_and_Geometry.md %} +[algorithms-list]: https://github.com/GuildCrafts/core-algorithms/blob/master/algorithms.md diff --git a/README.md b/README.md index 783e9c5..fa50efb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ # Core Algorithms +#158 Core Algorithms [Classic, Numeric, and Set] +#filthy-gerbil +Somaya Bounouar +http://jsdev.learnersguild.org/goals/158-Core_Algorithms-Classic_Numeric_and_Set.html + Tests and implementations for algorithms commonly used in job interviews. See the full list in the [algorithms.md](algorithms.md) file. From 7f2ed9ba9e698f93ecf4fd16af42df0a4bf87019 Mon Sep 17 00:00:00 2001 From: SomayaB Date: Mon, 24 Apr 2017 15:35:55 -0700 Subject: [PATCH 02/20] Complete makeChange algorithm w tests --- CONTRACT.md | 4 ++-- src/makeChange.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/CONTRACT.md b/CONTRACT.md index 3d3b54d..b9b1429 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -24,9 +24,9 @@ Complete **ONLY** the [Classic](https://github.com/GuildCrafts/core-algorithms/b ## Specifications -- [ ] Artifact produced is a fork of the [core-algorithms][core-algorithms] repo. +- [x] Artifact produced is a fork of the [core-algorithms][core-algorithms] repo. - [ ] Can run all tests with `npm test`. -- [ ] `makeChange()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [x] `makeChange()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [ ] Tests for `makeChange()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] `fizzBuzz()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [ ] Tests for `fizzBuzz()` exist. diff --git a/src/makeChange.js b/src/makeChange.js index 59d89b1..ef234a6 100644 --- a/src/makeChange.js +++ b/src/makeChange.js @@ -1,3 +1,46 @@ +// makeChange: +// +// Given a price and an amount paid, return the number of coins in each denomination that should be given as change. +// +// Note: because JavaScript is bad at decimal math, the inputs are given as integers that represent dollar + cent amounts, so 139 = $1.39. +// +// makeChange({ price: 100, amountGiven: 100 }) +// // => { quarters: 0, dimes: 0, nickels: 0, pennies: 0 } +// +// makeChange({ price: 159, amountGiven: 200 }) +// // => { quarters: 1, dimes: 1, nickels: 1, pennies: 1 } +// +// makeChange({ price: 432, amountGiven: 500 }) +// // => { quarters: 2, dimes: 1, nickels: 1, pennies: 3 } + + export default function makeChange({price, amountGiven}) { - // your code here + var change = { + quarters: 0, + dimes: 0, + nickels: 0, + pennies: 0, + } + var result = amountGiven - price + + if (result === 0) { + return change + } + while (result >= 25) { + result = result - 25 + change.quarters += 1 + } + while (result >= 10) { + result = result - 10 + change.dimes += 1 + } + while (result >= 5) { + result = result - 5 + change.nickels += 1 + } + while (result >= 1) { + result = result - 1 + change.pennies += 1 + } + return change } From 6f4b5d89f416c5d3cf98ba6a5a0cfa0779d1aa53 Mon Sep 17 00:00:00 2001 From: SomayaB Date: Mon, 24 Apr 2017 18:28:07 -0700 Subject: [PATCH 03/20] Add makeChange test for invalid inputs --- CONTRACT.md | 8 ++++---- src/makeChange.js | 12 ++++++++---- test/makeChange_test.js | 12 ++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/CONTRACT.md b/CONTRACT.md index b9b1429..1377525 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -25,11 +25,11 @@ Complete **ONLY** the [Classic](https://github.com/GuildCrafts/core-algorithms/b ## Specifications - [x] Artifact produced is a fork of the [core-algorithms][core-algorithms] repo. -- [ ] Can run all tests with `npm test`. +- [x] Can run all tests with `npm test`. - [x] `makeChange()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. -- [ ] Tests for `makeChange()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. -- [ ] `fizzBuzz()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. -- [ ] Tests for `fizzBuzz()` exist. +- [x] Tests for `makeChange()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [x] `fizzBuzz()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [x] Tests for `fizzBuzz()` exist. - [ ] `isPalindrome()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [ ] Tests for `isPalindrome()` exist with at least 2 unit tests using valid inputs. - [ ] `factorial()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. diff --git a/src/makeChange.js b/src/makeChange.js index ef234a6..28834c8 100644 --- a/src/makeChange.js +++ b/src/makeChange.js @@ -14,14 +14,18 @@ // // => { quarters: 2, dimes: 1, nickels: 1, pennies: 3 } -export default function makeChange({price, amountGiven}) { - var change = { +export default function makeChange(options) { + if (typeof options !== 'object') { + throw new Error('Invalid input format. Expected an object literal') + } + const {price, amountGiven} = options + let change = { quarters: 0, dimes: 0, nickels: 0, pennies: 0, } - var result = amountGiven - price + let result = amountGiven - price if (result === 0) { return change @@ -42,5 +46,5 @@ export default function makeChange({price, amountGiven}) { result = result - 1 change.pennies += 1 } - return change + return change } diff --git a/test/makeChange_test.js b/test/makeChange_test.js index d17098e..2ca1a8a 100644 --- a/test/makeChange_test.js +++ b/test/makeChange_test.js @@ -50,4 +50,16 @@ describe('makeChange()', function(){ pennies: 0, }) }) + + it('throws an error when given invalid inputs', function() { + expect(function(){ makeChange(100, 170) }).to.throw( + 'Invalid input format. Expected an object literal' + ) + }) + + it('throws an error when given no arguments', function() { + expect(function(){ makeChange() }).to.throw( + 'Invalid input format. Expected an object literal' + ) + }) }) From 2306267376bbf323f1b3a6bbb9f3b640331b31e4 Mon Sep 17 00:00:00 2001 From: SomayaB Date: Mon, 24 Apr 2017 18:29:35 -0700 Subject: [PATCH 04/20] Complete fizzBuzz algorithm w tests --- src/fizzBuzz.js | 26 ++++++++++++++++++++++++++ test/fizzBuzz_test.js | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/fizzBuzz.js create mode 100644 test/fizzBuzz_test.js diff --git a/src/fizzBuzz.js b/src/fizzBuzz.js new file mode 100644 index 0000000..e32601a --- /dev/null +++ b/src/fizzBuzz.js @@ -0,0 +1,26 @@ +// fizzBuzz +// +// Return an array of numbers from 1 to 100. +// +// For multiples of three, use the string Fizz instead of the number and for multiples of five replace with Buzz. +// +// For numbers which are multiples of both three and five replace with FizzBuzz. +// +// fizzBuzz() +// // => [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz', ...] + +export default function fizzBuzz() { + let fizzBuzzArray = [] + for (var i = 1; i <= 100; i++){ + if (i % 3 == 0 && i % 5 == 0) { + fizzBuzzArray.push('FizzBuzz') + } else if (i % 3 == 0) { + fizzBuzzArray.push('Fizz') + } else if (i % 5 == 0) { + fizzBuzzArray.push('Buzz') + } else { + fizzBuzzArray.push(i) + } + } + return fizzBuzzArray +} diff --git a/test/fizzBuzz_test.js b/test/fizzBuzz_test.js new file mode 100644 index 0000000..4fe4fe9 --- /dev/null +++ b/test/fizzBuzz_test.js @@ -0,0 +1,22 @@ +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('returns an array of 100 values', function() { + var fizzBuzzArray = fizzBuzz(100) + expect(fizzBuzzArray.length).to.deep.equal(100) + }) + + it("replace multiples of 3 as 'Fizz', multiples of 5 as 'Buzz' and multiples of 3 and 5 as 'FizzBuzz' and return numbers that aren't multiples of 3 or 5 ", function(){ + var fizzBuzzArray = fizzBuzz(100) + expect(fizzBuzzArray[2]).to.eql('Fizz') + expect(fizzBuzzArray[4]).to.eql('Buzz') + expect(fizzBuzzArray[14]).to.eql('FizzBuzz') + expect(fizzBuzzArray[1]).to.eql(2) + }) + }) From c8fdd34e7f21dcd44bee2752427ffbf838578256 Mon Sep 17 00:00:00 2001 From: SomayaB Date: Mon, 24 Apr 2017 18:29:56 -0700 Subject: [PATCH 05/20] WIP isPalindrome --- src/isPalindrome.js | 40 +++++++++++++++++++++++++++++++++++++++ test/isPalindrome_test.js | 2 ++ 2 files changed, 42 insertions(+) create mode 100644 src/isPalindrome.js create mode 100644 test/isPalindrome_test.js diff --git a/src/isPalindrome.js b/src/isPalindrome.js new file mode 100644 index 0000000..f499d03 --- /dev/null +++ b/src/isPalindrome.js @@ -0,0 +1,40 @@ +// isPalindrome +// +// Determine if a string is a palindrome. Return true or false. +// +// Ignore punctuation, spacing, and case sensitivity. +// +// isPalindrome('radar') +// // => true +// +// isPalindrome('bananas') +// // => false +// +// isPalindrome('A man, a plan, a canal: Panama') +// // => true + +export default function isPalindrome(string) { + var strToLowerCase = string.toLowerCase() + var strWithoutSpecialCharAndSpaces = strToLowerCase.replace(/[^a-zA-Z]/g, "") + var isPalindromeArray = strWithoutSpecialCharAndSpaces.split('') + + var shiftArray = [] + var popArray = [] + + for (var i = 0; i < isPalindromeArray.length; i++) { + shiftArray.push(isPalindromeArray.shift([i])) + popArray.push(isPalindromeArray.pop([i])) + } + console.log('shift', shiftArray) + console.log('pop', popArray) + //check if both arrays match + //return boolean +} + + +//regex to remove special characters and spaces +//2 empty arrays +//split string at characters +//shift from beginning of string into 1st array +//pop from end of string into 2nd array +//check if both arrays match diff --git a/test/isPalindrome_test.js b/test/isPalindrome_test.js new file mode 100644 index 0000000..285b803 --- /dev/null +++ b/test/isPalindrome_test.js @@ -0,0 +1,2 @@ +import { expect } from 'chai' +import isPalindrome from '../src/isPalindrome' From b445096764171c68fbc3ab934a7227ecf07892bc Mon Sep 17 00:00:00 2001 From: SomayaB Date: Tue, 25 Apr 2017 09:53:02 -0700 Subject: [PATCH 06/20] Complete isPalindrome algorithm w tests --- CONTRACT.md | 4 ++-- src/isPalindrome.js | 20 ++++++++------------ test/isPalindrome_test.js | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CONTRACT.md b/CONTRACT.md index 1377525..831bfbc 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -30,8 +30,8 @@ Complete **ONLY** the [Classic](https://github.com/GuildCrafts/core-algorithms/b - [x] Tests for `makeChange()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [x] `fizzBuzz()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [x] Tests for `fizzBuzz()` exist. -- [ ] `isPalindrome()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. -- [ ] Tests for `isPalindrome()` exist with at least 2 unit tests using valid inputs. +- [x] `isPalindrome()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [x] Tests for `isPalindrome()` exist with at least 2 unit tests using valid inputs. - [ ] `factorial()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [ ] Tests for `factorial()` exist with at least 2 unit tests using valid inputs. - [ ] `fibonacci()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. diff --git a/src/isPalindrome.js b/src/isPalindrome.js index f499d03..0a73cfa 100644 --- a/src/isPalindrome.js +++ b/src/isPalindrome.js @@ -25,16 +25,12 @@ export default function isPalindrome(string) { shiftArray.push(isPalindromeArray.shift([i])) popArray.push(isPalindromeArray.pop([i])) } - console.log('shift', shiftArray) - console.log('pop', popArray) - //check if both arrays match - //return boolean -} - + var shiftString = shiftArray.join('') + var popString = popArray.join('') -//regex to remove special characters and spaces -//2 empty arrays -//split string at characters -//shift from beginning of string into 1st array -//pop from end of string into 2nd array -//check if both arrays match + if (shiftString == popString) { + return true + } else { + return false + } +} diff --git a/test/isPalindrome_test.js b/test/isPalindrome_test.js index 285b803..53a013b 100644 --- a/test/isPalindrome_test.js +++ b/test/isPalindrome_test.js @@ -1,2 +1,18 @@ import { expect } from 'chai' import isPalindrome from '../src/isPalindrome' + +describe('isPalindrome', function() { + + it('should be a function', function(){ + expect(isPalindrome).to.be.a('function') + }) + + it('returns true if it is a palindrome', function() { + expect(isPalindrome('A man, a plan, a canal: Panama')).to.eql(true) + }) + + it('returns false if it is not a palindrome', function() { + expect(isPalindrome('bananas')).to.eql(false) + }) + +}) From 3a8074a067d3d92d060d470973d29748528d4e93 Mon Sep 17 00:00:00 2001 From: SomayaB Date: Tue, 25 Apr 2017 10:45:35 -0700 Subject: [PATCH 07/20] Clean up code --- src/isPalindrome.js | 4 ++-- src/makeChange.js | 2 +- test/isPalindrome_test.js | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/isPalindrome.js b/src/isPalindrome.js index 0a73cfa..8867c43 100644 --- a/src/isPalindrome.js +++ b/src/isPalindrome.js @@ -15,8 +15,8 @@ export default function isPalindrome(string) { var strToLowerCase = string.toLowerCase() - var strWithoutSpecialCharAndSpaces = strToLowerCase.replace(/[^a-zA-Z]/g, "") - var isPalindromeArray = strWithoutSpecialCharAndSpaces.split('') + var cleanStr = strToLowerCase.replace(/[^a-zA-Z]/g, "") + var isPalindromeArray = cleanStr.split('') var shiftArray = [] var popArray = [] diff --git a/src/makeChange.js b/src/makeChange.js index 28834c8..6269a1b 100644 --- a/src/makeChange.js +++ b/src/makeChange.js @@ -16,7 +16,7 @@ export default function makeChange(options) { if (typeof options !== 'object') { - throw new Error('Invalid input format. Expected an object literal') + throw new Error('Invalid input format. Expected an object') } const {price, amountGiven} = options let change = { diff --git a/test/isPalindrome_test.js b/test/isPalindrome_test.js index 53a013b..0b224f7 100644 --- a/test/isPalindrome_test.js +++ b/test/isPalindrome_test.js @@ -14,5 +14,4 @@ describe('isPalindrome', function() { it('returns false if it is not a palindrome', function() { expect(isPalindrome('bananas')).to.eql(false) }) - }) From 82dc880b0b8d8d779b1654dcafd25f590814dded Mon Sep 17 00:00:00 2001 From: SomayaB Date: Tue, 25 Apr 2017 11:00:58 -0700 Subject: [PATCH 08/20] Complete factorial algorithm w tests --- CONTRACT.md | 4 ++-- src/factorial.js | 17 +++++++++++++++++ test/factorial_test.js | 14 ++++++++++++++ test/makeChange_test.js | 4 ++-- 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 src/factorial.js create mode 100644 test/factorial_test.js diff --git a/CONTRACT.md b/CONTRACT.md index 831bfbc..31fbf2d 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -32,8 +32,8 @@ Complete **ONLY** the [Classic](https://github.com/GuildCrafts/core-algorithms/b - [x] Tests for `fizzBuzz()` exist. - [x] `isPalindrome()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [x] Tests for `isPalindrome()` exist with at least 2 unit tests using valid inputs. -- [ ] `factorial()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. -- [ ] Tests for `factorial()` exist with at least 2 unit tests using valid inputs. +- [x] `factorial()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [x] Tests for `factorial()` exist with at least 2 unit tests using valid inputs. - [ ] `fibonacci()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [ ] Tests for `fibonacci()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] `collatzConjecture()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. diff --git a/src/factorial.js b/src/factorial.js new file mode 100644 index 0000000..c15d20a --- /dev/null +++ b/src/factorial.js @@ -0,0 +1,17 @@ +// factorial +// +// Return the factorial of a number. +// +// factorial(5) +// // => 120 + +export default function factorial(num) { +var factorialElements = [num] +for (var i = num; i > 1; i--) { +factorialElements.push(i - 1) +} +console.log('array', factorialElements) +return factorialElements.reduce(function(a,b){ +return a*b +}, 1) +} diff --git a/test/factorial_test.js b/test/factorial_test.js new file mode 100644 index 0000000..12daa9e --- /dev/null +++ b/test/factorial_test.js @@ -0,0 +1,14 @@ +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('returns the factorial of any fiven number', function() { + expect(factorial(5)).to.eql(120) + expect(factorial(4)).to.eql(24) + }) +}) diff --git a/test/makeChange_test.js b/test/makeChange_test.js index 2ca1a8a..9956816 100644 --- a/test/makeChange_test.js +++ b/test/makeChange_test.js @@ -53,13 +53,13 @@ describe('makeChange()', function(){ it('throws an error when given invalid inputs', function() { expect(function(){ makeChange(100, 170) }).to.throw( - 'Invalid input format. Expected an object literal' + 'Invalid input format. Expected an object' ) }) it('throws an error when given no arguments', function() { expect(function(){ makeChange() }).to.throw( - 'Invalid input format. Expected an object literal' + 'Invalid input format. Expected an object' ) }) }) From 25d0906f8bdf35630aaad47268f19397eae806e6 Mon Sep 17 00:00:00 2001 From: SomayaB Date: Tue, 25 Apr 2017 12:55:30 -0700 Subject: [PATCH 09/20] Complete fibonacci algorithm w tests --- CONTRACT.md | 4 ++-- src/fibonacci.js | 24 ++++++++++++++++++++++++ test/fibonacci_test.js | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/fibonacci.js create mode 100644 test/fibonacci_test.js diff --git a/CONTRACT.md b/CONTRACT.md index 31fbf2d..c70420a 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -34,8 +34,8 @@ Complete **ONLY** the [Classic](https://github.com/GuildCrafts/core-algorithms/b - [x] Tests for `isPalindrome()` exist with at least 2 unit tests using valid inputs. - [x] `factorial()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [x] Tests for `factorial()` exist with at least 2 unit tests using valid inputs. -- [ ] `fibonacci()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. -- [ ] Tests for `fibonacci()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [x] `fibonacci()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [x] Tests for `fibonacci()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] `collatzConjecture()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [ ] Tests for `collatzConjecture()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] `setUnion()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. diff --git a/src/fibonacci.js b/src/fibonacci.js new file mode 100644 index 0000000..88a9a4a --- /dev/null +++ b/src/fibonacci.js @@ -0,0 +1,24 @@ +// fibonacci +// +// Return an array of Fibonacci numbers to the nth position. +// +// fibonacci(10) +// // => [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] + +export default function fibonacci(num) { + if (typeof num !== 'number') { + throw new Error('Invalid input format. Expected a number') + } + var first = 0 + var second = 1 + var result + var fibonacciArr = [0] + + for (var i = 1; i < num; i++) { + result = first + second + first = second + second = result + fibonacciArr.push(first) + } + return fibonacciArr +} diff --git a/test/fibonacci_test.js b/test/fibonacci_test.js new file mode 100644 index 0000000..06154f6 --- /dev/null +++ b/test/fibonacci_test.js @@ -0,0 +1,18 @@ +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('returns an array of Fibonacci numbers to the nth position.', function() { + expect(fibonacci(10)).to.eql([0, 1, 1, 2, 3, 5, 8, 13, 21, 34]) + expect(fibonacci(5)).to.eql([0, 1, 1, 2, 3]) + }) + + it('throws an error when given invalid inputs', function() { + expect(function() {fibonacci('five') }).to.throw('Invalid input format. Expected a number') + }) +}) From 2e657470900797801077b5094f85db7bc56b54bf Mon Sep 17 00:00:00 2001 From: SomayaB Date: Tue, 25 Apr 2017 14:12:18 -0700 Subject: [PATCH 10/20] Complete collatzConjecture algorithm w tests --- CONTRACT.md | 4 ++-- src/collatzConjecture.js | 32 ++++++++++++++++++++++++++++++++ test/collatzConjecture_test.js | 18 ++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/collatzConjecture.js create mode 100644 test/collatzConjecture_test.js diff --git a/CONTRACT.md b/CONTRACT.md index c70420a..5b01d97 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -36,8 +36,8 @@ Complete **ONLY** the [Classic](https://github.com/GuildCrafts/core-algorithms/b - [x] Tests for `factorial()` exist with at least 2 unit tests using valid inputs. - [x] `fibonacci()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [x] Tests for `fibonacci()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. -- [ ] `collatzConjecture()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. -- [ ] Tests for `collatzConjecture()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [x] `collatzConjecture()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [x] Tests for `collatzConjecture()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] `setUnion()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [ ] Tests for `setUnion()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] `setIntersection()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. diff --git a/src/collatzConjecture.js b/src/collatzConjecture.js new file mode 100644 index 0000000..3f5a5e1 --- /dev/null +++ b/src/collatzConjecture.js @@ -0,0 +1,32 @@ +// collatzConjecture +// +// Return the Collatz sequence for a given number. +// +// The Collatz sequence for any positive integer n is defined as follows: +// +// If n is even, divide it by 2 to get n / 2. If n is odd, multiply it by 3 and add 1 to obtain 3n + 1. Repeat the process until you reach 1. +// collatzConjecture(1) +// // => [1] +// +// collatzConjecture(7) +// // => [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1] + + +export default function collatzConjecture(num) { + if (!Number.isInteger(num) || num < 0) { + throw new Error('Invalid input format. Expected a positive integer') + } + let collatzArr = [num] + let result = num + + while (result > 1) { + if (result % 2 === 0) { + result = result / 2 + collatzArr.push(result) + } else { + result = (result * 3) + 1 + collatzArr.push(result) + } + } + return collatzArr +} diff --git a/test/collatzConjecture_test.js b/test/collatzConjecture_test.js new file mode 100644 index 0000000..c895ca0 --- /dev/null +++ b/test/collatzConjecture_test.js @@ -0,0 +1,18 @@ +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('returns a Collatz sequence for any positive integer', 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(3)).to.eql([3, 10, 5, 16, 8, 4, 2, 1]) + }) + + it('throws an error for any invalid inputs', function() { + expect(function() {collatzConjecture(-1)}).to.throw('Invalid input format. Expected a positive integer') + expect(function() {collatzConjecture('seven')}).to.throw('Invalid input format. Expected a positive integer') + }) +}) From e07820ee2d2f791f918546138f17d07ce5692820 Mon Sep 17 00:00:00 2001 From: SomayaB Date: Tue, 25 Apr 2017 14:14:17 -0700 Subject: [PATCH 11/20] Clean code --- src/factorial.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/factorial.js b/src/factorial.js index c15d20a..cb8372f 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -6,12 +6,11 @@ // // => 120 export default function factorial(num) { -var factorialElements = [num] -for (var i = num; i > 1; i--) { -factorialElements.push(i - 1) -} -console.log('array', factorialElements) -return factorialElements.reduce(function(a,b){ -return a*b -}, 1) + var factorialElements = [num] + for (var i = num; i > 1; i--) { + factorialElements.push(i - 1) + } + return factorialElements.reduce(function(a,b){ + return a*b + }, 1) } From cecde9c8b3cb5a8f5bb94539efda2f737b23ed72 Mon Sep 17 00:00:00 2001 From: SomayaB Date: Tue, 25 Apr 2017 15:45:44 -0700 Subject: [PATCH 12/20] Complete setUnion algorithm w tests --- CONTRACT.md | 4 ++-- src/setUnion.js | 22 ++++++++++++++++++++++ test/setUnion_test.js | 20 ++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/setUnion.js create mode 100644 test/setUnion_test.js diff --git a/CONTRACT.md b/CONTRACT.md index 5b01d97..1eb880f 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -38,8 +38,8 @@ Complete **ONLY** the [Classic](https://github.com/GuildCrafts/core-algorithms/b - [x] Tests for `fibonacci()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [x] `collatzConjecture()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [x] Tests for `collatzConjecture()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. -- [ ] `setUnion()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. -- [ ] Tests for `setUnion()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [x] `setUnion()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [x] Tests for `setUnion()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] `setIntersection()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [ ] Tests for `setIntersection()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] `setComplement()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. diff --git a/src/setUnion.js b/src/setUnion.js new file mode 100644 index 0000000..79f5b94 --- /dev/null +++ b/src/setUnion.js @@ -0,0 +1,22 @@ +// setUnion +// +// Return the union of two sets. +// +// const a = [1, 2, 3, 4] +// const b = [2, 4, 6, 8] +// setUnion(a, b) +// // => [1, 2, 3, 4, 6, 8] + +export default function setUnion(a, b){ + if (!Array.isArray(a) || !Array.isArray(b)){ + throw new Error('Invalid input format. Expected two arrays') + } + let concatArr = a.concat(b) + let sortedArr = concatArr.sort() + + function isUnique(value, index, array){ + return array.indexOf(value) === index + } + let filteredArr = sortedArr.filter(isUnique) + return filteredArr +} diff --git a/test/setUnion_test.js b/test/setUnion_test.js new file mode 100644 index 0000000..6813273 --- /dev/null +++ b/test/setUnion_test.js @@ -0,0 +1,20 @@ +import { expect } from 'chai' +import setUnion from '../src/setUnion' + +describe('setUnion', function(){ + + it('should be a function', function() { + expect(setUnion).to.be.a('function') + }) + + it('returns the union of two sets', function() { + expect(setUnion([1,2,3,4],[2,4,6,8])).to.eql([1, 2, 3, 4, 6, 8]) + expect(setUnion([2,3,4,4], [1,2,3,4]).to.eqal([1,2,3,4]) + }) + + it('throws an error when given invalid inputs', function() { + expect(function() {setUnion('string')}).to.throw( + 'Invalid input format. Expected two arrays' + ) + }) +}) From 80095c9daaccf2c8d0c378436246b7d8d4dbcefa Mon Sep 17 00:00:00 2001 From: SomayaB Date: Tue, 25 Apr 2017 16:10:59 -0700 Subject: [PATCH 13/20] Complete setIntersection w tests --- CONTRACT.md | 10 +++++----- src/setIntersection.js | 23 +++++++++++++++++++++++ test/setIntersection_test.js | 20 ++++++++++++++++++++ test/setUnion_test.js | 2 +- 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 src/setIntersection.js create mode 100644 test/setIntersection_test.js diff --git a/CONTRACT.md b/CONTRACT.md index 1eb880f..28e9da0 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -40,19 +40,19 @@ Complete **ONLY** the [Classic](https://github.com/GuildCrafts/core-algorithms/b - [x] Tests for `collatzConjecture()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [x] `setUnion()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [x] Tests for `setUnion()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. -- [ ] `setIntersection()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. -- [ ] Tests for `setIntersection()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [x] `setIntersection()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [x] Tests for `setIntersection()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] `setComplement()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [ ] Tests for `setComplement()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] `setSymmetricDifference()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [ ] Tests for `setSymmetricDifference()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] Repository includes a README file with basic installation and setup instructions. -- [ ] All dependencies are properly declared in `package.json`. +- [x] All dependencies are properly declared in `package.json`. - [ ] All major features are added via pull requests with a clear description and concise commit messages. - [ ] Code uses a linter and there are no linting errors. - [ ] Variables, functions, files, etc. have appropriate and meaningful names. -- [ ] Functions are small and serve a single purpose. -- [ ] The artifact produced is properly licensed, preferably with the [MIT license][mit-license]. +- [] Functions are small and serve a single purpose. +- [x] The artifact produced is properly licensed, preferably with the [MIT license][mit-license]. ### Stretch diff --git a/src/setIntersection.js b/src/setIntersection.js new file mode 100644 index 0000000..a5a1118 --- /dev/null +++ b/src/setIntersection.js @@ -0,0 +1,23 @@ +// setIntersection +// +// Return the intersection of two sets. +// +// const a = [1, 2, 3, 4] +// const b = [2, 4, 6, 8] +// setIntersection(a, b) +// // => [2, 4] + + +export default function setIntersection(a, b){ + if ( !Array.isArray(a) || !Array.isArray(b) ) { + throw new Error('Invalid input format. Expected two arrays') + } + let concatArr = a.concat(b) + let sortedArr = concatArr.sort() + + function isDuplicate(value, index, array){ + return array.indexOf(value) !== index + } + let filteredArr = sortedArr.filter(isDuplicate) + return filteredArr +} diff --git a/test/setIntersection_test.js b/test/setIntersection_test.js new file mode 100644 index 0000000..871a6a0 --- /dev/null +++ b/test/setIntersection_test.js @@ -0,0 +1,20 @@ +import { expect } from 'chai' +import setIntersection from '../src/setIntersection' + +describe('setIntersection', function(){ + + it('should be a function', function() { + expect(setIntersection).to.be.a('function') + }) + + it('returns the intersection of two sets', function () { + expect(setIntersection([1, 2, 3, 4],[2, 4, 6, 8])).to.eql([2,4]) + expect(setIntersection([82,90,1], [1, 2, 90])).to.eql([1,90]) + }) + + it('throws an error when given invalid inputs', function() { + expect(function() {setIntersection('string')}).to.throw( + 'Invalid input format. Expected two arrays' + ) + }) +}) diff --git a/test/setUnion_test.js b/test/setUnion_test.js index 6813273..154031e 100644 --- a/test/setUnion_test.js +++ b/test/setUnion_test.js @@ -9,7 +9,7 @@ describe('setUnion', function(){ it('returns the union of two sets', function() { expect(setUnion([1,2,3,4],[2,4,6,8])).to.eql([1, 2, 3, 4, 6, 8]) - expect(setUnion([2,3,4,4], [1,2,3,4]).to.eqal([1,2,3,4]) + expect(setUnion([2,3,4,4],[1,2,3,4])).to.eql([1,2,3,4]) }) it('throws an error when given invalid inputs', function() { From d9697a3d0065681bb38a91544651082b4242231b Mon Sep 17 00:00:00 2001 From: SomayaB Date: Tue, 25 Apr 2017 17:53:59 -0700 Subject: [PATCH 14/20] Complete setComplement algorithm w tests --- CONTRACT.md | 4 ++-- src/setComplement.js | 22 ++++++++++++++++++++++ test/setComplement_test.js | 27 +++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/setComplement.js create mode 100644 test/setComplement_test.js diff --git a/CONTRACT.md b/CONTRACT.md index 28e9da0..c91e6fb 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -42,8 +42,8 @@ Complete **ONLY** the [Classic](https://github.com/GuildCrafts/core-algorithms/b - [x] Tests for `setUnion()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [x] `setIntersection()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [x] Tests for `setIntersection()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. -- [ ] `setComplement()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. -- [ ] Tests for `setComplement()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [x] `setComplement()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [x] Tests for `setComplement()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] `setSymmetricDifference()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [ ] Tests for `setSymmetricDifference()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] Repository includes a README file with basic installation and setup instructions. diff --git a/src/setComplement.js b/src/setComplement.js new file mode 100644 index 0000000..208675c --- /dev/null +++ b/src/setComplement.js @@ -0,0 +1,22 @@ +// setComplement +// +// Return the complement of two sets. +// +// const a = [1, 2, 3, 4] +// const b = [2, 4, 6, 8] +// setComplement(a, b) +// // => [6, 8] + + +export default function setComplement(setA, setB) { + if ( !Array.isArray(setA) || !Array.isArray(setB) ) { + throw new Error('Invalid input format. Expected two arrays') + } + let complementArray = [] + for(let element of setB) { + if(!setA.includes(element)) { + complementArray.push(element) + } + } + return complementArray + } diff --git a/test/setComplement_test.js b/test/setComplement_test.js new file mode 100644 index 0000000..a8159ec --- /dev/null +++ b/test/setComplement_test.js @@ -0,0 +1,27 @@ +import { expect } from 'chai' +import setComplement from '../src/setComplement' + +describe('setComplement', function(){ + + it('should be a function', function() { + expect(setComplement).to.be.a('function') + }) + + it('should show the items from set B that are not present in set A', function() { + const setA = ['fluffy', 'cat', 'scratchy'] + const setB = ['scratchy', 'fluffy', 'dog'] + expect(setComplement(setA, setB)).to.eql(['dog']) + }) + + it('should show empty set if no items in B are not in A', function() { + const setA = ['fluffy', 'cat', 'scratchy'] + const setB = ['scratchy', 'fluffy'] + expect(setComplement(setA, setB)).to.eql([]) + }) + + it('throws an error when given invalid inputs', function() { + expect(function() {setComplement({}, false)}).to.throw( + 'Invalid input format. Expected two arrays' + ) + }) +}) From 41d8ce9c525ac0098d22f5cd7aa2a07e396ee464 Mon Sep 17 00:00:00 2001 From: SomayaB Date: Wed, 26 Apr 2017 14:54:34 -0700 Subject: [PATCH 15/20] Complete setSymmetricDifference algorithm w tests --- CONTRACT.md | 10 +++++----- src/factorial.js | 22 ++++++++++++++------- src/setSymmetricDifference.js | 30 +++++++++++++++++++++++++++++ test/setSymmetricDifference_test.js | 20 +++++++++++++++++++ 4 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 src/setSymmetricDifference.js create mode 100644 test/setSymmetricDifference_test.js diff --git a/CONTRACT.md b/CONTRACT.md index c91e6fb..7b1f973 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -44,14 +44,14 @@ Complete **ONLY** the [Classic](https://github.com/GuildCrafts/core-algorithms/b - [x] Tests for `setIntersection()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [x] `setComplement()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [x] Tests for `setComplement()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. -- [ ] `setSymmetricDifference()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. -- [ ] Tests for `setSymmetricDifference()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. +- [x] `setSymmetricDifference()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. +- [x] Tests for `setSymmetricDifference()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [ ] Repository includes a README file with basic installation and setup instructions. - [x] All dependencies are properly declared in `package.json`. -- [ ] All major features are added via pull requests with a clear description and concise commit messages. +- [x] All major features are added via pull requests with a clear description and concise commit messages. - [ ] Code uses a linter and there are no linting errors. -- [ ] Variables, functions, files, etc. have appropriate and meaningful names. -- [] Functions are small and serve a single purpose. +- [x] Variables, functions, files, etc. have appropriate and meaningful names. +- [ ] Functions are small and serve a single purpose. - [x] The artifact produced is properly licensed, preferably with the [MIT license][mit-license]. ### Stretch diff --git a/src/factorial.js b/src/factorial.js index cb8372f..3b13a65 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -6,11 +6,19 @@ // // => 120 export default function factorial(num) { - var factorialElements = [num] - for (var i = num; i > 1; i--) { - factorialElements.push(i - 1) + var accumulator = num + for (var i = num; i > 1; i--) { + accumulator = accumulator * (i - 1) + } + return accumulator } - return factorialElements.reduce(function(a,b){ - return a*b - }, 1) -} + +//Other way: +// var factorialElements = [num] +// for (var i = num; i > 1; i--) { +// factorialElements.push(i - 1) +// } +// return factorialElements.reduce(function(a,b){ +// return a*b +// }, 1) +// } diff --git a/src/setSymmetricDifference.js b/src/setSymmetricDifference.js new file mode 100644 index 0000000..945cec0 --- /dev/null +++ b/src/setSymmetricDifference.js @@ -0,0 +1,30 @@ +// setSymmetricDifference +// +// Return the symmetric difference of two sets. +// +// const a = [1, 2, 3, 4] +// const b = [2, 4, 6, 8] +// setSymmetricDifference(a, b) +// // => [1, 3, 6, 8] + + +export default function setSymmetricDifference(setA, setB) { + if ( !Array.isArray(setA) || !Array.isArray(setB) ) { + throw new Error('Invalid input format. Expected two arrays') + } + let complementArray = [] + + for(let element of setB) { + if(!setA.includes(element)) { + complementArray.push(element) + } + } + for(let element of setA){ + if(!setB.includes(element)) { + complementArray.push(element) + } + } + return complementArray.sort() + } + +// diff --git a/test/setSymmetricDifference_test.js b/test/setSymmetricDifference_test.js new file mode 100644 index 0000000..11f9554 --- /dev/null +++ b/test/setSymmetricDifference_test.js @@ -0,0 +1,20 @@ +import { expect } from 'chai' +import setSymmetricDifference from '../src/setSymmetricDifference' + + + +describe('setSymmetricDifference', function() { + + it('should be a function', function() { + expect(setSymmetricDifference).to.be.a('function') + }) + + it('returns the symmetric difference of two sets', function() { + expect(setSymmetricDifference([1, 2, 3, 4], [2, 4, 6, 8])).to.eql([1, 3, 6, 8]) + }) + + it('throws an error when given invalid inputs', function() { + expect(function() {setSymmetricDifference('string', [1,2])}). + to.throw('Invalid input format. Expected two arrays') + }) +}) From 8c3b3523aa5b191f2669ebe1010bca82cf9799c3 Mon Sep 17 00:00:00 2001 From: SomayaB Date: Wed, 26 Apr 2017 17:52:41 -0700 Subject: [PATCH 16/20] Add ESLint and clean code --- .eslintrc.json | 28 ++++++++++++++++++++++++++++ README.md | 9 ++++++++- package.json | 1 + src/factorial.js | 8 ++++---- src/isPalindrome.js | 2 +- src/setComplement.js | 2 +- src/setSymmetricDifference.js | 4 ++-- test/fizzBuzz_test.js | 10 +++++----- 8 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 .eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..0cf2f93 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,28 @@ +{ + "env": { + "es6": true, + "node": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "sourceType": "module" + }, + "rules": { + "indent": [ + "error", + 2 + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "single" + ], + "semi": [ + "error", + "never" + ] + } +} diff --git a/README.md b/README.md index fa50efb..f492cc5 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,14 @@ Base repository for the [Core Algorithms](http://jsdev.learnersguild.org/goals/1 ## Installation and Setup -_Fill this out_ + + +Use the "npm i" command to install your dependencies. + +Use the "npm run test" command to run your tests in the terminal. + +Use the "npm install --save-dev eslint" command to install the linter ESlint. +Run the "eslint --init" command to configure ESlint. ## Usage and Examples diff --git a/package.json b/package.json index 71f93c5..809abf3 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "babel-preset-env": "^1.1.4", "babel-register": "^6.18.0", "chai": "~1.8.0", + "eslint": "^3.19.0", "mocha": "2.0.1" }, "scripts": { diff --git a/src/factorial.js b/src/factorial.js index 3b13a65..20ff181 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -6,12 +6,12 @@ // // => 120 export default function factorial(num) { - var accumulator = num - for (var i = num; i > 1; i--) { + var accumulator = num + for (var i = num; i > 1; i--) { accumulator = accumulator * (i - 1) - } - return accumulator } + return accumulator +} //Other way: // var factorialElements = [num] diff --git a/src/isPalindrome.js b/src/isPalindrome.js index 8867c43..714cee7 100644 --- a/src/isPalindrome.js +++ b/src/isPalindrome.js @@ -15,7 +15,7 @@ export default function isPalindrome(string) { var strToLowerCase = string.toLowerCase() - var cleanStr = strToLowerCase.replace(/[^a-zA-Z]/g, "") + var cleanStr = strToLowerCase.replace(/[^a-zA-Z]/g, '') var isPalindromeArray = cleanStr.split('') var shiftArray = [] diff --git a/src/setComplement.js b/src/setComplement.js index 208675c..75210b3 100644 --- a/src/setComplement.js +++ b/src/setComplement.js @@ -19,4 +19,4 @@ export default function setComplement(setA, setB) { } } return complementArray - } +} diff --git a/src/setSymmetricDifference.js b/src/setSymmetricDifference.js index 945cec0..6db53a9 100644 --- a/src/setSymmetricDifference.js +++ b/src/setSymmetricDifference.js @@ -13,7 +13,7 @@ export default function setSymmetricDifference(setA, setB) { throw new Error('Invalid input format. Expected two arrays') } let complementArray = [] - + for(let element of setB) { if(!setA.includes(element)) { complementArray.push(element) @@ -25,6 +25,6 @@ export default function setSymmetricDifference(setA, setB) { } } return complementArray.sort() - } +} // diff --git a/test/fizzBuzz_test.js b/test/fizzBuzz_test.js index 4fe4fe9..7f6cb4c 100644 --- a/test/fizzBuzz_test.js +++ b/test/fizzBuzz_test.js @@ -14,9 +14,9 @@ describe('fizzBuzz()', function(){ it("replace multiples of 3 as 'Fizz', multiples of 5 as 'Buzz' and multiples of 3 and 5 as 'FizzBuzz' and return numbers that aren't multiples of 3 or 5 ", function(){ var fizzBuzzArray = fizzBuzz(100) - expect(fizzBuzzArray[2]).to.eql('Fizz') - expect(fizzBuzzArray[4]).to.eql('Buzz') - expect(fizzBuzzArray[14]).to.eql('FizzBuzz') - expect(fizzBuzzArray[1]).to.eql(2) - }) + expect(fizzBuzzArray[2]).to.eql('Fizz') + expect(fizzBuzzArray[4]).to.eql('Buzz') + expect(fizzBuzzArray[14]).to.eql('FizzBuzz') + expect(fizzBuzzArray[1]).to.eql(2) }) +}) From 50024850250e88f46b17335d63295ac1b616105a Mon Sep 17 00:00:00 2001 From: SomayaB Date: Thu, 27 Apr 2017 12:38:48 -0700 Subject: [PATCH 17/20] Fix linting errors --- .eslintrc.json | 3 ++- CONTRACT.md | 4 ++-- README.md | 5 ++--- test/fizzBuzz_test.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 0cf2f93..8b2834c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,8 @@ { "env": { "es6": true, - "node": true + "node": true, + "mocha": true }, "extends": "eslint:recommended", "parserOptions": { diff --git a/CONTRACT.md b/CONTRACT.md index 7b1f973..84a88cf 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -49,9 +49,9 @@ Complete **ONLY** the [Classic](https://github.com/GuildCrafts/core-algorithms/b - [ ] Repository includes a README file with basic installation and setup instructions. - [x] All dependencies are properly declared in `package.json`. - [x] All major features are added via pull requests with a clear description and concise commit messages. -- [ ] Code uses a linter and there are no linting errors. +- [x] Code uses a linter and there are no linting errors. - [x] Variables, functions, files, etc. have appropriate and meaningful names. -- [ ] Functions are small and serve a single purpose. +- [x] Functions are small and serve a single purpose. - [x] The artifact produced is properly licensed, preferably with the [MIT license][mit-license]. ### Stretch diff --git a/README.md b/README.md index f492cc5..9c13d91 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,13 @@ Base repository for the [Core Algorithms](http://jsdev.learnersguild.org/goals/1 ## Installation and Setup - - Use the "npm i" command to install your dependencies. Use the "npm run test" command to run your tests in the terminal. Use the "npm install --save-dev eslint" command to install the linter ESlint. -Run the "eslint --init" command to configure ESlint. + Use the "eslint --init" command to configure ESlint. + Use the "eslint [filename or folder name]" command to lint through your files. ## Usage and Examples diff --git a/test/fizzBuzz_test.js b/test/fizzBuzz_test.js index 7f6cb4c..befb983 100644 --- a/test/fizzBuzz_test.js +++ b/test/fizzBuzz_test.js @@ -12,7 +12,7 @@ describe('fizzBuzz()', function(){ expect(fizzBuzzArray.length).to.deep.equal(100) }) - it("replace multiples of 3 as 'Fizz', multiples of 5 as 'Buzz' and multiples of 3 and 5 as 'FizzBuzz' and return numbers that aren't multiples of 3 or 5 ", function(){ + it('replace multiples of 3 as \'Fizz\', multiples of 5 as \'Buzz\' and multiples of 3 and 5 as \'FizzBuzz\' and return numbers that aren\'t multiples of 3 or 5 ', function(){ var fizzBuzzArray = fizzBuzz(100) expect(fizzBuzzArray[2]).to.eql('Fizz') expect(fizzBuzzArray[4]).to.eql('Buzz') From c8b7754bc31cebc920766c7d22b3da7d45cb1c5c Mon Sep 17 00:00:00 2001 From: SomayaB Date: Thu, 27 Apr 2017 15:13:56 -0700 Subject: [PATCH 18/20] Add setup instructions in README file --- CONTRACT.md | 2 +- README.md | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/CONTRACT.md b/CONTRACT.md index 84a88cf..d228caf 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -46,7 +46,7 @@ Complete **ONLY** the [Classic](https://github.com/GuildCrafts/core-algorithms/b - [x] Tests for `setComplement()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. - [x] `setSymmetricDifference()` algorithm is implemented according to the description in [algorithms.md][algorithms-list]. - [x] Tests for `setSymmetricDifference()` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs. -- [ ] Repository includes a README file with basic installation and setup instructions. +- [x] Repository includes a README file with basic installation and setup instructions. - [x] All dependencies are properly declared in `package.json`. - [x] All major features are added via pull requests with a clear description and concise commit messages. - [x] Code uses a linter and there are no linting errors. diff --git a/README.md b/README.md index 9c13d91..18769e8 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,10 @@ Base repository for the [Core Algorithms](http://jsdev.learnersguild.org/goals/1 ## Installation and Setup -Use the "npm i" command to install your dependencies. +Use the "npm i" command to install the dependencies. -Use the "npm run test" command to run your tests in the terminal. +Use the "npm run test" command to run the tests in the terminal. -Use the "npm install --save-dev eslint" command to install the linter ESlint. +Use the "npm install --save-dev eslint" command to install the linter ESlint in the JSON file. Use the "eslint --init" command to configure ESlint. Use the "eslint [filename or folder name]" command to lint through your files. - -## Usage and Examples - -_...and this_ From 6267dad1a0b68620e59053ac6f3996ebab0f9669 Mon Sep 17 00:00:00 2001 From: SomayaB Date: Thu, 27 Apr 2017 17:01:08 -0700 Subject: [PATCH 19/20] Fix setIntersection to account for edge case --- .babelrc | 2 +- src/setIntersection.js | 21 +++++++++++++++------ test/collatzConjecture_test.js | 1 + test/setIntersection_test.js | 1 + 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.babelrc b/.babelrc index 2f01e1d..002b4aa 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,3 @@ { "presets": ["env"] -} \ No newline at end of file +} diff --git a/src/setIntersection.js b/src/setIntersection.js index a5a1118..3201e1c 100644 --- a/src/setIntersection.js +++ b/src/setIntersection.js @@ -8,16 +8,25 @@ // // => [2, 4] -export default function setIntersection(a, b){ - if ( !Array.isArray(a) || !Array.isArray(b) ) { +export default function setIntersection(setA, setB) { + if ( !Array.isArray(setA) || !Array.isArray(setB) ) { throw new Error('Invalid input format. Expected two arrays') } - let concatArr = a.concat(b) - let sortedArr = concatArr.sort() + let complementArray = [] + for(let element of setB) { + if(setA.includes(element)) { + complementArray.push(element) + } + } + for(let element of setA){ + if(setB.includes(element)) { + complementArray.push(element) + } + } function isDuplicate(value, index, array){ return array.indexOf(value) !== index } - let filteredArr = sortedArr.filter(isDuplicate) - return filteredArr + let filteredArr = complementArray.filter(isDuplicate) + return filteredArr.sort() } diff --git a/test/collatzConjecture_test.js b/test/collatzConjecture_test.js index c895ca0..62674f2 100644 --- a/test/collatzConjecture_test.js +++ b/test/collatzConjecture_test.js @@ -6,6 +6,7 @@ describe('collatzConjecture()', function(){ it('should be a function', function(){ expect(collatzConjecture).to.be.a('function') }) + it('returns a Collatz sequence for any positive integer', 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(3)).to.eql([3, 10, 5, 16, 8, 4, 2, 1]) diff --git a/test/setIntersection_test.js b/test/setIntersection_test.js index 871a6a0..5a76ef5 100644 --- a/test/setIntersection_test.js +++ b/test/setIntersection_test.js @@ -10,6 +10,7 @@ describe('setIntersection', function(){ it('returns the intersection of two sets', function () { expect(setIntersection([1, 2, 3, 4],[2, 4, 6, 8])).to.eql([2,4]) expect(setIntersection([82,90,1], [1, 2, 90])).to.eql([1,90]) + expect(setIntersection([1,1,2,3,4], [2,4,6,8])).to.eql([2,4]) }) it('throws an error when given invalid inputs', function() { From 61634618b5c55ea19ceceaff5e5b3142fa68f276 Mon Sep 17 00:00:00 2001 From: SomayaB Date: Thu, 27 Apr 2017 17:17:21 -0700 Subject: [PATCH 20/20] Refactor to ES6 --- src/collatzConjecture.js | 4 +++- src/factorial.js | 8 +++++--- src/fibonacci.js | 14 ++++++++------ src/fizzBuzz.js | 6 ++++-- src/isPalindrome.js | 20 +++++++++++--------- src/makeChange.js | 4 +++- src/setComplement.js | 4 +++- src/setIntersection.js | 4 +++- src/setSymmetricDifference.js | 4 ++-- src/setUnion.js | 4 +++- test/collatzConjecture_test.js | 4 ++-- test/factorial_test.js | 2 +- test/fibonacci_test.js | 2 +- test/fizzBuzz_test.js | 2 +- test/isPalindrome_test.js | 2 +- test/makeChange_test.js | 2 +- test/setComplement_test.js | 2 +- test/setIntersection_test.js | 2 +- test/setSymmetricDifference_test.js | 4 ++-- test/setUnion_test.js | 2 +- 20 files changed, 57 insertions(+), 39 deletions(-) diff --git a/src/collatzConjecture.js b/src/collatzConjecture.js index 3f5a5e1..e4c8348 100644 --- a/src/collatzConjecture.js +++ b/src/collatzConjecture.js @@ -12,7 +12,7 @@ // // => [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1] -export default function collatzConjecture(num) { +let collatzConjecture = num => { if (!Number.isInteger(num) || num < 0) { throw new Error('Invalid input format. Expected a positive integer') } @@ -30,3 +30,5 @@ export default function collatzConjecture(num) { } return collatzArr } + +module.exports = { collatzConjecture } diff --git a/src/factorial.js b/src/factorial.js index 20ff181..867ed5e 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -5,14 +5,16 @@ // factorial(5) // // => 120 -export default function factorial(num) { - var accumulator = num - for (var i = num; i > 1; i--) { +let factorial = num => { + let accumulator = num + for (let i = num; i > 1; i--) { accumulator = accumulator * (i - 1) } return accumulator } +module.exports = { factorial } + //Other way: // var factorialElements = [num] // for (var i = num; i > 1; i--) { diff --git a/src/fibonacci.js b/src/fibonacci.js index 88a9a4a..8c17b2f 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -5,16 +5,16 @@ // fibonacci(10) // // => [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] -export default function fibonacci(num) { +let fibonacci = num => { if (typeof num !== 'number') { throw new Error('Invalid input format. Expected a number') } - var first = 0 - var second = 1 - var result - var fibonacciArr = [0] + let first = 0 + let second = 1 + let result + let fibonacciArr = [0] - for (var i = 1; i < num; i++) { + for (let i = 1; i < num; i++) { result = first + second first = second second = result @@ -22,3 +22,5 @@ export default function fibonacci(num) { } return fibonacciArr } + +module.exports = { fibonacci } diff --git a/src/fizzBuzz.js b/src/fizzBuzz.js index e32601a..17922e7 100644 --- a/src/fizzBuzz.js +++ b/src/fizzBuzz.js @@ -9,9 +9,9 @@ // fizzBuzz() // // => [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz', ...] -export default function fizzBuzz() { +let fizzBuzz = () => { let fizzBuzzArray = [] - for (var i = 1; i <= 100; i++){ + for (let i = 1; i <= 100; i++){ if (i % 3 == 0 && i % 5 == 0) { fizzBuzzArray.push('FizzBuzz') } else if (i % 3 == 0) { @@ -24,3 +24,5 @@ export default function fizzBuzz() { } return fizzBuzzArray } + +module.exports = { fizzBuzz } diff --git a/src/isPalindrome.js b/src/isPalindrome.js index 714cee7..2008062 100644 --- a/src/isPalindrome.js +++ b/src/isPalindrome.js @@ -13,20 +13,20 @@ // isPalindrome('A man, a plan, a canal: Panama') // // => true -export default function isPalindrome(string) { - var strToLowerCase = string.toLowerCase() - var cleanStr = strToLowerCase.replace(/[^a-zA-Z]/g, '') - var isPalindromeArray = cleanStr.split('') +let isPalindrome = string => { + let strToLowerCase = string.toLowerCase() + let cleanStr = strToLowerCase.replace(/[^a-zA-Z]/g, '') + let isPalindromeArray = cleanStr.split('') - var shiftArray = [] - var popArray = [] + let shiftArray = [] + let popArray = [] - for (var i = 0; i < isPalindromeArray.length; i++) { + for (let i = 0; i < isPalindromeArray.length; i++) { shiftArray.push(isPalindromeArray.shift([i])) popArray.push(isPalindromeArray.pop([i])) } - var shiftString = shiftArray.join('') - var popString = popArray.join('') + let shiftString = shiftArray.join('') + let popString = popArray.join('') if (shiftString == popString) { return true @@ -34,3 +34,5 @@ export default function isPalindrome(string) { return false } } + +module.exports = { isPalindrome } diff --git a/src/makeChange.js b/src/makeChange.js index 6269a1b..ae6e03d 100644 --- a/src/makeChange.js +++ b/src/makeChange.js @@ -14,7 +14,7 @@ // // => { quarters: 2, dimes: 1, nickels: 1, pennies: 3 } -export default function makeChange(options) { +let makeChange = options => { if (typeof options !== 'object') { throw new Error('Invalid input format. Expected an object') } @@ -48,3 +48,5 @@ export default function makeChange(options) { } return change } + +module.exports = { makeChange } diff --git a/src/setComplement.js b/src/setComplement.js index 75210b3..fc30fbd 100644 --- a/src/setComplement.js +++ b/src/setComplement.js @@ -8,7 +8,7 @@ // // => [6, 8] -export default function setComplement(setA, setB) { +let setComplement = (setA, setB) => { if ( !Array.isArray(setA) || !Array.isArray(setB) ) { throw new Error('Invalid input format. Expected two arrays') } @@ -20,3 +20,5 @@ export default function setComplement(setA, setB) { } return complementArray } + +module.exports = { setComplement } diff --git a/src/setIntersection.js b/src/setIntersection.js index 3201e1c..b655c49 100644 --- a/src/setIntersection.js +++ b/src/setIntersection.js @@ -8,7 +8,7 @@ // // => [2, 4] -export default function setIntersection(setA, setB) { +let setIntersection = (setA, setB) => { if ( !Array.isArray(setA) || !Array.isArray(setB) ) { throw new Error('Invalid input format. Expected two arrays') } @@ -30,3 +30,5 @@ export default function setIntersection(setA, setB) { let filteredArr = complementArray.filter(isDuplicate) return filteredArr.sort() } + +module.exports = { setIntersection } diff --git a/src/setSymmetricDifference.js b/src/setSymmetricDifference.js index 6db53a9..2384ff6 100644 --- a/src/setSymmetricDifference.js +++ b/src/setSymmetricDifference.js @@ -8,7 +8,7 @@ // // => [1, 3, 6, 8] -export default function setSymmetricDifference(setA, setB) { +let setSymmetricDifference = (setA, setB) => { if ( !Array.isArray(setA) || !Array.isArray(setB) ) { throw new Error('Invalid input format. Expected two arrays') } @@ -27,4 +27,4 @@ export default function setSymmetricDifference(setA, setB) { return complementArray.sort() } -// +module.exports = { setSymmetricDifference } diff --git a/src/setUnion.js b/src/setUnion.js index 79f5b94..350e7db 100644 --- a/src/setUnion.js +++ b/src/setUnion.js @@ -7,7 +7,7 @@ // setUnion(a, b) // // => [1, 2, 3, 4, 6, 8] -export default function setUnion(a, b){ +let setUnion = (a, b) => { if (!Array.isArray(a) || !Array.isArray(b)){ throw new Error('Invalid input format. Expected two arrays') } @@ -20,3 +20,5 @@ export default function setUnion(a, b){ let filteredArr = sortedArr.filter(isUnique) return filteredArr } + +module.exports = { setUnion } diff --git a/test/collatzConjecture_test.js b/test/collatzConjecture_test.js index 62674f2..4149886 100644 --- a/test/collatzConjecture_test.js +++ b/test/collatzConjecture_test.js @@ -1,12 +1,12 @@ import { expect } from 'chai' -import collatzConjecture from '../src/collatzConjecture' +import { collatzConjecture } from '../src/collatzConjecture' describe('collatzConjecture()', function(){ it('should be a function', function(){ expect(collatzConjecture).to.be.a('function') }) - + it('returns a Collatz sequence for any positive integer', 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(3)).to.eql([3, 10, 5, 16, 8, 4, 2, 1]) diff --git a/test/factorial_test.js b/test/factorial_test.js index 12daa9e..ef9b7d6 100644 --- a/test/factorial_test.js +++ b/test/factorial_test.js @@ -1,5 +1,5 @@ import { expect } from 'chai' -import factorial from '../src/factorial' +import { factorial } from '../src/factorial' describe('factorial()', function(){ diff --git a/test/fibonacci_test.js b/test/fibonacci_test.js index 06154f6..6c9c221 100644 --- a/test/fibonacci_test.js +++ b/test/fibonacci_test.js @@ -1,5 +1,5 @@ import { expect } from 'chai' -import fibonacci from '../src/fibonacci' +import { fibonacci } from '../src/fibonacci' describe ('fibonacci', function(){ diff --git a/test/fizzBuzz_test.js b/test/fizzBuzz_test.js index befb983..ff58373 100644 --- a/test/fizzBuzz_test.js +++ b/test/fizzBuzz_test.js @@ -1,5 +1,5 @@ import { expect } from 'chai' -import fizzBuzz from '../src/fizzBuzz' +import { fizzBuzz } from '../src/fizzBuzz' describe('fizzBuzz()', function(){ diff --git a/test/isPalindrome_test.js b/test/isPalindrome_test.js index 0b224f7..70c2d77 100644 --- a/test/isPalindrome_test.js +++ b/test/isPalindrome_test.js @@ -1,5 +1,5 @@ import { expect } from 'chai' -import isPalindrome from '../src/isPalindrome' +import { isPalindrome } from '../src/isPalindrome' describe('isPalindrome', function() { diff --git a/test/makeChange_test.js b/test/makeChange_test.js index 9956816..e512241 100644 --- a/test/makeChange_test.js +++ b/test/makeChange_test.js @@ -1,5 +1,5 @@ import { expect } from 'chai' -import makeChange from '../src/makeChange' +import { makeChange } from '../src/makeChange' describe('makeChange()', function(){ diff --git a/test/setComplement_test.js b/test/setComplement_test.js index a8159ec..c3e7121 100644 --- a/test/setComplement_test.js +++ b/test/setComplement_test.js @@ -1,5 +1,5 @@ import { expect } from 'chai' -import setComplement from '../src/setComplement' +import { setComplement } from '../src/setComplement' describe('setComplement', function(){ diff --git a/test/setIntersection_test.js b/test/setIntersection_test.js index 5a76ef5..383836a 100644 --- a/test/setIntersection_test.js +++ b/test/setIntersection_test.js @@ -1,5 +1,5 @@ import { expect } from 'chai' -import setIntersection from '../src/setIntersection' +import { setIntersection } from '../src/setIntersection' describe('setIntersection', function(){ diff --git a/test/setSymmetricDifference_test.js b/test/setSymmetricDifference_test.js index 11f9554..c52a57e 100644 --- a/test/setSymmetricDifference_test.js +++ b/test/setSymmetricDifference_test.js @@ -1,5 +1,5 @@ import { expect } from 'chai' -import setSymmetricDifference from '../src/setSymmetricDifference' +import { setSymmetricDifference } from '../src/setSymmetricDifference' @@ -12,7 +12,7 @@ describe('setSymmetricDifference', function() { it('returns the symmetric difference of two sets', function() { expect(setSymmetricDifference([1, 2, 3, 4], [2, 4, 6, 8])).to.eql([1, 3, 6, 8]) }) - + it('throws an error when given invalid inputs', function() { expect(function() {setSymmetricDifference('string', [1,2])}). to.throw('Invalid input format. Expected two arrays') diff --git a/test/setUnion_test.js b/test/setUnion_test.js index 154031e..74f7ef9 100644 --- a/test/setUnion_test.js +++ b/test/setUnion_test.js @@ -1,5 +1,5 @@ import { expect } from 'chai' -import setUnion from '../src/setUnion' +import { setUnion } from '../src/setUnion' describe('setUnion', function(){