Skip to content
Open
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
23 changes: 23 additions & 0 deletions src/collatzConjecture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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 @@
function factorialize(num) {
let inputValue = num;
let factorial = 1;
for (let x = num; x >= 1; x--) {
factorial *= x;
}
return factorial;
}
12 changes: 12 additions & 0 deletions src/fibonacci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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 @@
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 @@

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")); */
17 changes: 16 additions & 1 deletion src/makeChange.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
export default function makeChange({price, amountGiven}) {
// your code here
// your code here
let coins = {quarters: 25, dimes: 10, nickels: 5, pennies: 1 }
let changeDue = amountGiven - price

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

coins[key] = numberOfCoins

}
return coins;
}
26 changes: 26 additions & 0 deletions src/setUnion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function returnUnion(a,b) {
const a = [1, 2, 3, 4]
const b = [2, 4, 6, 8]
let unionValues = [];


// create index counter to loop through array
// while checking for matches/equality/less of index
// push proper values to array







}

// initalize function (a,b)
// declare constants and set empty array to hold union values
// determine the first values of the two arrays

// if one is less than the other push the lesser value to array
// if equal push the value to array
// else return union values
// return unionVAluesm
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)
})

})