Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Core Algorithms
# Core Algorithms #teamName premium-partridge #Aisha Ortiz and Thomas Dunn

Tests and implementations for algorithms commonly used in job interviews. See the full list in the [algorithms.md](algorithms.md) file.

Expand Down
10 changes: 10 additions & 0 deletions algorithmTest1Week3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>

</head>

<body>
<script src="src/makeChange.js"/>
</body>
</html>
2 changes: 1 addition & 1 deletion algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Return the factorial of a number.
factorial(5)
// => 120
```

fac
#### fibonacci

Return an array of Fibonacci numbers to the _nth_ position.
Expand Down
1 change: 1 addition & 0 deletions core-algorithms
Submodule core-algorithms added at 2713bc
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"description": "Tests and implementations for algorithms commonly used in job interviews.",
"private": false,
"version": "0.0.0",
"repository": {
"type": "git",
"url": "git+https://github.com/aishao/core-algorithms"
},
"author": "Aisha , Thomas",
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-preset-env": "^1.1.4",
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 assembleCollatz(num) {
let collatzArray = [num];

while ( collatzArray[collatzArray.length-1] !== 1) {
let lastNumber = collatzArray[collatzArray.length-1];

if (lastNumber % 2 === 0) {
collatzArray.push(lastNumber / 2)
} else {
collatzArray.push((3 * lastNumber) + 1)
}
}
return collatzArray;
}
console.log(assembleCollatz(7));

//initalize function (num)
// create empty arraySequence
// while (the last number of arraySequence is not 1)
// if num is even
// push num / 2 to the array
// else if push 3num + 1 to arraySequence
// return sequence
8 changes: 8 additions & 0 deletions src/factorial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function factorialize(num) {
let inputValue = num;
let factorial = 1;
for (let x = num; x >= 1; x--) {
factorial *= x;
}
return factorial;
}
14 changes: 14 additions & 0 deletions src/fibonacci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

export default function assembleFibonacci(nth) {
let a = 0, b = 1, f = 1;
let fibonacciArray = [a,b];
for (let i = 2; i < nth; i++) {
f = a + b;
a = b;
b = f;
fibonacciArray.push(f);
}
return fibonacciArray;
}

//console.log(assembleFibonacci(10));
14 changes: 14 additions & 0 deletions src/fizzBuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default let list = new Array(100);

for (let i = 0; i < 100; i++) {
list[i] = i + 1; // $$c populates the array. +1 is necessary because arrays are 0 index based and you want to store 1 - 100 in it, NOT 0-99.{

//list[i] is equal to an index in the array
if (list[i] % 5 === 0 && list[i] % 3 === 0) { // populate multiples of both five && three with "FIZZBUZZ"
list[i] = "FizzBuzz"
} else if (list[i] % 5 === 0) { // populate multiples of five with "BUZZ"
list[i] = "Buzz"
} else if (list[i] % 3 === 0) { // populate multiples of three with "FIZZ"
list[i] = "Fizz"
}
}
23 changes: 23 additions & 0 deletions src/isPalindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

export default function isPalindrome(str) {

str = str.replace(/[^0-9a-z]/gi, "").toLowerCase();
let palindrome = str.split("").reverse().join("");
if (str === palindrome) {
return true;
} else {
return false;
}
}

/*console.log(

isPalindrome('radar')
=> true

isPalindrome('bananas')
=> false

isPalindrome('A man, a plan, a canal: Panama')
=> true
isPalindrome("A man, a plan, a canal: Panama")); */
20 changes: 19 additions & 1 deletion src/makeChange.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
export default function makeChange({price, amountGiven}) {
// your code here
// your code here
let coins = {quarters: 25, dimes: 10, nickels: 5, pennies: 1 }

for(let key in coins) {
let numberOfCoins = Math.floor(changeDue / coins[key])
/*takes the changeDue divides it by coin section of quarters (25) resulting in a
decimal of 1.64, then Math.floor round down to the nearest integer which is
1 (<= the given number) and assigns it to the variable numberOfCoins.
*/

changeDue -= coins[keys] * numberOfCoins

changeDue -= coins[key] * numberOfCoins


coins[key] = numberOfCoins

}
return coins;
}
6 changes: 6 additions & 0 deletions src/setUnion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function setUnion(myArray) {

return [...new Set(myArray)]; // .. Es6 version of .unique method

}
console.log(setUnion());
16 changes: 16 additions & 0 deletions test/factorial_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect } from 'chai'
import factorialize from '../src/factorial'

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

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

it('returns the outout of the factorial)', function(){
expect(factorialize(5)).to.equal(120)
expect(factorialize(12)).to.equal(479001600)
expect(factorialize(8)).to.equal(40320)

})
})
Empty file added test/fizzBuzzTests.js
Empty file.
20 changes: 20 additions & 0 deletions test/isPalindrome_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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 the input is a Palindrome', function(){
expect(isPalindrome('racecar')).to.equal(true)
})
it('returns true if the input is a Palindrome', function(){
expect(isPalindrome('trevor')).to.equal(false)
})
it('returns true if the input is a Palindrome', function(){
expect(isPalindrome('A man, a plan, a canal: Panama')).to.equal(true)
})

})
18 changes: 18 additions & 0 deletions test/setUnion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect } from 'chai'
import setUnion from '../src/setUnion'

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

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

it('returns an array', function(){
expect(setUnion([1, 2, 3])).to.deep.equal([1, 2, 3])
})

it ('seeks one of a kind in the array', function(){
expect(setUnion([1, 2, 3, 4, 2, 4, 6, 8,])).to.deep.equal([1, 2, 3, 4, 6, 8])
})

})