Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e67d9f0
makeChange passing all tests
kamilambert May 8, 2017
6323adf
Merge pull request #1 from kamilambert/make-change
kamilambert May 8, 2017
be4efa6
all fizzBuzz tests passing
kamilambert May 8, 2017
32e0b91
Merge pull request #2 from kamilambert/fizzBuzz
kamilambert May 8, 2017
b489119
all isPalindrome tests passing
kamilambert May 8, 2017
dab7e5f
Merge pull request #3 from kamilambert/isPalidrome
kamilambert May 8, 2017
f61fc07
all factorial tests passing
kamilambert May 8, 2017
fd13e9c
Merge pull request #4 from kamilambert/factorial
kamilambert May 8, 2017
bbbc6d6
all fibonacci tests passing
kamilambert May 8, 2017
495a61f
Merge pull request #5 from kamilambert/fibonacci
kamilambert May 8, 2017
8446d29
all collatzConjecture tests passing
kamilambert May 8, 2017
cb8e983
Merge pull request #6 from kamilambert/collatz
kamilambert May 8, 2017
ebb9ce2
all setUnion tests passing
kamilambert May 8, 2017
b58527d
Merge pull request #7 from kamilambert/setUnion
kamilambert May 8, 2017
181fedd
all setIntersections tests passing
kamilambert May 8, 2017
193c23e
Merge pull request #8 from kamilambert/setIntersection
kamilambert May 8, 2017
1d2633f
all setComplement tests passing
kamilambert May 8, 2017
7192a37
Merge pull request #9 from kamilambert/setComplement
kamilambert May 8, 2017
99ed290
all symmetricDif tests passing
kamilambert May 9, 2017
3eaa6a8
Merge pull request #10 from kamilambert/symmetricDif
kamilambert May 9, 2017
2674dc8
readme updated with completed list items
kamilambert May 9, 2017
8a2daf7
Merge pull request #11 from kamilambert/readme
kamilambert May 9, 2017
204d2b9
makeChange updated with invalid input test
kamilambert May 9, 2017
1a09344
Merge pull request #12 from kamilambert/makeChange
kamilambert May 9, 2017
b7b5915
additional factorial test added
kamilambert May 9, 2017
ff0f5cd
added eslint.js and eslint to package.json
kamilambert May 9, 2017
0467dd6
Merge pull request #13 from kamilambert/eslint
kamilambert May 9, 2017
2dca0f4
readme updated with setup and examples
kamilambert May 12, 2017
cee867b
Merge pull request #14 from kamilambert/read-me
kamilambert May 12, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = {
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"never"
]
}
};
72 changes: 65 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,71 @@
# Core Algorithms
# Installation and Setup

Tests and implementations for algorithms commonly used in job interviews. See the full list in the [algorithms.md](algorithms.md) file.
Installing your dependencies from the package.json file using ```npm install```

Base repository for the [Core Algorithms](http://jsdev.learnersguild.org/goals/123) goal.
## Usage and Examples

## Installation and Setup
### Factorial

_Fill this out_
Returns factorial of number passed in

## Usage and Examples
```
let multiplyNumbers = []

for (let i = input; i > 1; i--) {
multiplyNumbers.push(i)
}
return multiplyNumbers.reduce(function(a, b) {return a * b})
}
```

### Factorial Testing

```
import { expect } from 'chai'
import factorial from '../src/factorial'

describe.only('factorial()', function(){

it('should be a function', function(){
expect(factorial).to.be.a('function')
})

it('returns factorial of number passed in', function(){
expect(factorial(5)).to.deep.equal(120)
expect(factorial(10)).to.deep.equal(3628800)
})
})
```


# Core Algorithms [Classic, Numeric, Set]

_...and this_
- [x] Artifact produced is a fork of the [core-algorithms][core-algorithms] repo.
- [x] Can run all tests with npm test.
- [x] ```makeChange()``` algorithm is implemented according to the description in algorithms.md.
- [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.
- [x] Tests for ```fizzBuzz()``` exist.
- [x] ```isPalindrome()``` algorithm is implemented according to the description in algorithms.md.
- [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.
- [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.
- [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.
- [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.
- [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.
- [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.
- [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.
- [x] Tests for ```setSymmetricDifference()``` exist with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs.
- [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.
- [x] Variables, functions, files, etc. have appropriate and meaningful names.
- [x] Functions are small and serve a single purpose.
- [x] The artifact produced is properly licensed, preferably with the [MIT license][mit-license].
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
"description": "Tests and implementations for algorithms commonly used in job interviews.",
"private": false,
"version": "0.0.0",
"devDependencies": {
"dependencies": {
"babel-cli": "^6.18.0",
"babel-preset-env": "^1.1.4",
"babel-register": "^6.18.0",
"chai": "~1.8.0",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.1.3",
"eslint-plugin-import": "^2.2.0",
"mocha": "2.0.1"
},
"scripts": {
Expand Down
23 changes: 23 additions & 0 deletions src/collatzConjecture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default function collatzConjecture(input) {

let finalArray = [],
currentNumber = input

if (!Number.isInteger(input)) {
return undefined
} else if (input === 1) {
return [1];
} else {
while (currentNumber !== 1) {
if (currentNumber % 2 === 0) {
finalArray.push(currentNumber)
currentNumber = currentNumber / 2
} else {
finalArray.push(currentNumber)
currentNumber = (currentNumber * 3) + 1
}
}
finalArray.push(currentNumber)
return finalArray
}
}
9 changes: 9 additions & 0 deletions src/factorial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function factorial(input) {

let multiplyNumbers = []

for (let i = input; i > 1; i--) {
multiplyNumbers.push(i)
}
return multiplyNumbers.reduce(function(a, b) {return a * b})
}
18 changes: 18 additions & 0 deletions src/fibonacci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default function fibonacci(input) {

const fibArray = [0, 1]

if (!Number.isInteger(input) || input < 1) {
return undefined
} else if (input === 1) {
return [0]
} else if (input === 2) {
return fibArray
} else {
for (let i = 2; i < input; i++) {
let current = fibArray[i - 1] + fibArray[i - 2]
fibArray.push(current)
}
}
return fibArray
}
17 changes: 17 additions & 0 deletions src/fizzBuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default function fizzBuzz() {

let fizzBuzzArray = []

for (let i = 1; i <= 100; i++) {
if (i % 15 === 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
}
7 changes: 7 additions & 0 deletions src/isPalindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function isPalindrome(input) {

const condensedString = input.replace(/[\W_]+/g, '').toLowerCase()
const reversedString = condensedString.split('').reverse().join('')
return condensedString === reversedString

}
31 changes: 29 additions & 2 deletions src/makeChange.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
export default function makeChange({price, amountGiven}) {
// your code here
export default function makeChange({price, amountGiven}) {

let changeNeeded = amountGiven - price,
coinChange = {quarters: 0, dimes: 0, nickels: 0, pennies: 0}

if (amountGiven < price) {
return 'Gimme more money!'
}

while (changeNeeded >= 25) {
coinChange.quarters++
changeNeeded -= 25
}

while (changeNeeded >= 10) {
coinChange.dimes++
changeNeeded -= 10
}

while (changeNeeded >= 5) {
coinChange.nickels++
changeNeeded -= 5
}

while (changeNeeded >= 1) {
coinChange.pennies++
changeNeeded -= 1
}
return coinChange
}
8 changes: 8 additions & 0 deletions src/setComplement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function setComplement(firstSet, secondSet) {

const intersection = new Set([...secondSet].filter(x => !firstSet.includes(x)))

if (!firstSet || !secondSet) {
return undefined
} return Array.from(intersection)
}
8 changes: 8 additions & 0 deletions src/setIntersection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function setIntersecion(firstSet, secondSet) {

const intersection = new Set([...firstSet].filter(x => secondSet.includes(x)))

if (!firstSet || !secondSet) {
return undefined
} return Array.from(intersection)
}
14 changes: 14 additions & 0 deletions src/setSymmetricDifference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default function setSymmetricDifference(firstSet, secondSet) {

const intersection = new Set([...firstSet].filter(x => !secondSet.includes(x)))
const intersection2 = new Set([...secondSet].filter(x => !firstSet.includes(x)))

const intersectionArray = Array.from(intersection)
const intersectionArray2 = Array.from(intersection2)

const setArray = intersectionArray.concat(intersectionArray2)

if (!firstSet || !secondSet) {
return undefined
} return setArray
}
9 changes: 9 additions & 0 deletions src/setUnion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function setUnion(firstSet, secondSet) {

if (!firstSet || !secondSet) {
return undefined
} else {
let finalSet = new Set([...firstSet, ...secondSet])
return Array.from(finalSet)
}
}
38 changes: 38 additions & 0 deletions test/collatzConjecture_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { expect } from 'chai';
import collatzConjecture from '../src/collatzConjecture';

describe.only('collatzConjecture()', () => {
it('should be a function', () => {
expect(collatzConjecture).to.be.a('function');
});

it('should give you an array of [1] when handed 1', () => {
expect(collatzConjecture(1)).to.deep.equal([1]);
});

it('should give you a lengthy array when handed 7', () => {
expect(collatzConjecture(7)).to.deep.equal(
[7,
22,
11,
34,
17,
52,
26,
13,
40,
20,
10,
5,
16,
8,
4,
2,
1]);
});

it('should not evaluate non-numerical values', () => {
expect(collatzConjecture('string')).to.equal(undefined);
expect(collatzConjecture(['string'])).to.equal(undefined);
});
});
14 changes: 14 additions & 0 deletions test/factorial_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect } from 'chai'
import factorial from '../src/factorial'

describe.only('factorial()', function(){

it('should be a function', function(){
expect(factorial).to.be.a('function')
})

it('returns an array of numbers 1-100, fizz for multiples of 3, buzz for multiples of 5, fizzbuzz for multiples of 3 and five', function(){
expect(factorial(5)).to.deep.equal(120)
expect(factorial(10)).to.deep.equal(3628800)
})
})
26 changes: 26 additions & 0 deletions test/fibonacci_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect } from 'chai';
import fibonacci from '../src/fibonacci';

describe.only('fibonacci()', () => {
it('should be a function', () => {
expect(fibonacci).to.be.a('function');
});

it('should output an array', () => {
expect(fibonacci(1)).to.be.a('array');
});

it('should give a proper array', () => {
expect(fibonacci(10)).to.deep.equal([0, 1, 1, 2, 3, 5, 8, 13, 21, 34]);
});

it('should not try to run the function with the values of empty things', () => {
expect(fibonacci({})).to.equal(undefined);
expect(fibonacci('')).to.equal(undefined);
expect(fibonacci([])).to.equal(undefined);
});

it('should not let you plug in negitive integers', () => {
expect(fibonacci(-5)).to.equal(undefined);
});
});
Loading