diff --git a/package.json b/package.json index 71f93c5..5330355 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "mocha": "2.0.1" }, "scripts": { + "build": "babel src -d lib", "test": "mocha --compilers js:babel-register" } } diff --git a/src/FizzBuzz.js b/src/FizzBuzz.js new file mode 100644 index 0000000..634175b --- /dev/null +++ b/src/FizzBuzz.js @@ -0,0 +1,27 @@ +export default function fizzbuzz(arr) { +} + +/*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', ...] + + +fizzBuzz (arr) => { + let arr = []; +for(const i = 0; i < arr.length; i ++) { + if(n % 3 === 0) { + console.log ("fizz") + } + else if (n % 5 === 0) { + console.log ("buzz") + else { + console.log ("fizzbuzz") + } +} diff --git a/src/collatzconjecture.js b/src/collatzconjecture.js new file mode 100644 index 0000000..ea40e21 --- /dev/null +++ b/src/collatzconjecture.js @@ -0,0 +1,23 @@ +export default function collatzconjecture({}) { + + + +/*collatzConjecture(1) +// => [1] + +collatzConjecture(7) +// => [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]*/ + + function collatzconjecture (n) { + + const seq = 0 + while ( i > 1){ + if(n % 2 ) { + n/2; + } else if (n % 3) { + (3 * n) + 1; + } + return seq + } + } +} diff --git a/src/factorial.js b/src/factorial.js new file mode 100644 index 0000000..0a3fb2c --- /dev/null +++ b/src/factorial.js @@ -0,0 +1,26 @@ +export default function factorial {()} { + + +/*Factorial = the product of an integer and all the integers below it; e.g., factorial four ( 4! ) is equal to 24. + + + +Return the factorial of a number.*/ + +//factorial(5) +// => 120 + + + +factorial (x) => { + if(x === 0) { + return 1; + } + if(x < 0 ) { + return undefined; + } + for(var i = x; --i; ) { + x *= i; + } + return x; +} diff --git a/src/fibonacci.js b/src/fibonacci.js new file mode 100644 index 0000000..9ab701d --- /dev/null +++ b/src/fibonacci.js @@ -0,0 +1,25 @@ +export default function fibonnaci({}){ + +//npm test + + + + + + +fibonacci(10) +// => [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] + + +fibonacci(num) => { + var x = 1, y = 0, temp; + + while (num >= 0){ + temp = x; + x = x + y; + y = temp; + num--; + } + + return y; +} diff --git a/src/isPalindrome.js b/src/isPalindrome.js new file mode 100644 index 0000000..90fc596 --- /dev/null +++ b/src/isPalindrome.js @@ -0,0 +1,35 @@ +export default function isPalindrome({string}) { + + + +/*Palindrome = a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run. + +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*/ + + + +Palindrome(string) => { + const reverseString = ''; + for(const k in string){ + reverseString += string[(string.length - k) - 1]; + } + if(string === reverseString){ + console.log('true'); + } else { + console.log("false"); + } + } +} diff --git a/src/setIntersection.js b/src/setIntersection.js new file mode 100644 index 0000000..13d6ac2 --- /dev/null +++ b/src/setIntersection.js @@ -0,0 +1,28 @@ +export default function setIntersection {()} { + + + + + +/*Return the intersection of two sets. + +const a = [1, 2, 3, 4] +const b = [2, 4, 6, 8] +setIntersection(a, b) +// => [2, 4]*/ + + + +setIntersection () => { +let arr = [1, 2, 3, 4] +let b = [2, 4, 6, 8] +setIntersection(a, b) +let sorted_arr = arr.slice().sort(); +let results = []; +for (let i = 0; i < arr.length - 1; i++) { + if (sorted_arr[i + 1] == sorted_arr[i]) { + results.push(sorted_arr[i]); + } +} + +console.log(results); diff --git a/src/setSymmetricDifference.js b/src/setSymmetricDifference.js new file mode 100644 index 0000000..c805e38 --- /dev/null +++ b/src/setSymmetricDifference.js @@ -0,0 +1,33 @@ +export default function setSymmetricDifference({}) { + +//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] + + + setSymmetricDifference (a,b) => { + let ans = [], cnts = {}; + for (let i = 0; i < arguments.length; i++){ + arguments[i].forEach(function(item) { + if (cnts.hasOwnProperty(item)) { + // increase cnt + ++cnts[item].cnt; + } else { + // initalize cnt and value + cnts[item] = {cnt: 1, val: item}; + } + }); + } + for (let item in cnts) { + if (cnts.hasOwnProperty(item) && cnts[item].cnt === 1) { + ans.push(cnts[item].val); + } + } + + return ans; +} diff --git a/src/setUnion.js b/src/setUnion.js new file mode 100644 index 0000000..fcd17fb --- /dev/null +++ b/src/setUnion.js @@ -0,0 +1,40 @@ +export default function 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]*/ + +setUnion (arr) => //could be a quicksort algorithm + +const union = []; + for (const i = 0; i < arr.length; i++) { + for (const j = 0; i < arr.length; j++){ + const repeat = array[i]; + if (union.indexOf(repeat) !== -1 ) { + return true; + } + union.push(repeat); + } + return false; + } + } +} + +/*function hasDuplicates(array) { + var valuesSoFar = []; + for (var i = 0; i < array.length; ++i) { + var value = array[i]; + if (valuesSoFar.indexOf(value) !== -1) { + return true; + } + valuesSoFar.push(value); + } + return false; +} +*/ diff --git a/src/setcomplement.js b/src/setcomplement.js new file mode 100644 index 0000000..5fe811c --- /dev/null +++ b/src/setcomplement.js @@ -0,0 +1,21 @@ +export defautl function setComplement ({}) { + + + + + +/*setComplement + +Return the complement of two sets.*/ + +/*const a = [1, 2, 3, 4] +const b = [2, 4, 6, 8] +setComplement(a, b) +// => [6, 8]*/ + + + set.complement = (a, b) => { + return process(a, b, function(freq) { + return freq === 1; + }); + }; diff --git a/test/collatzconjecture_test.js b/test/collatzconjecture_test.js new file mode 100644 index 0000000..5daa86b --- /dev/null +++ b/test/collatzconjecture_test.js @@ -0,0 +1,19 @@ +import { expect } from 'chai' +import collatzconjecture from '../src/collatzconjecture' + + + + +//expect ('collatzConjecture_test()', function () { + + describe.only('collatzconjecture_test()', function() { + + it('should be a function', function(){ + expect.collatzconjecture.to.be.a('function') + }) + + +//describe('collatzConjecture_test()'{ +// expect.factorial_test.to.be.a('function') +// +}) diff --git a/test/factorial_test.js b/test/factorial_test.js new file mode 100644 index 0000000..c8f630f --- /dev/null +++ b/test/factorial_test.js @@ -0,0 +1,24 @@ +import { expect } from 'chai' +import factorial from '../src/factorial' + + + + + + +describe('factorial_test()', function(){ + + it('should be a function', function(){ + expect.factorial_test.to.be.a('function') +}) + + +it('returns a factorial', function(){ + const change = factorial({}) +}) + + + +it('returns factorial', function(){ + expect(factorial({return undefined if < 0)} +}) diff --git a/test/fibonacci_test.js b/test/fibonacci_test.js new file mode 100644 index 0000000..96aeb60 --- /dev/null +++ b/test/fibonacci_test.js @@ -0,0 +1,22 @@ +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 true when fibonacci = fibonacci', function(){ + //const Pali = fibonacci({price: 100, amountGiven: 100}) + //expect(change).to.be.an('object') + }) +}) + + +describe.only('fibonacci', () => { + + it( 'Returns sum to 10()' => { + expect( sumEvenFibs(10) ).to.equal( 44 ) + }) +}) diff --git a/test/fizzBuzz_test.js b/test/fizzBuzz_test.js new file mode 100644 index 0000000..cde34da --- /dev/null +++ b/test/fizzBuzz_test.js @@ -0,0 +1,19 @@ +import { expect } from 'chai' +import fizzBuzz from '../src/fizzBuzz' + + +describe('FizzBuzz()', function(){ + + it('should be a function', function(){ + expect.FizzBuzz.to.be.a('function') +}) + + +it('returns Fizz when there are multiples of three', function(){ + expect(fizzBuzz({multiplesOfThree: wordReturned: Fizz})).to.deep.equal({ + multiplesOfThree: amountGiven: Fizz}) + + +it('returns Buzz when there are multiples of five', function(){ + expect(fizzBuzz({multiplesOfFive: wordReturned: Buzz})).to.deep.equal({ + multiplesOfFive: amountGiven: Buzz}) diff --git a/test/isPalindrome.js b/test/isPalindrome.js new file mode 100644 index 0000000..8de9e6c --- /dev/null +++ b/test/isPalindrome.js @@ -0,0 +1,21 @@ +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 when isPalindrome = palindrome', function(){ + const Pali = isPalindrome(}) + expect(change).to.be.an('object') + }) +}) + +it('returns false if isPalindrome is not a Palindrome,' function(){ + expect(isPalindrome({})).to.deep.equal({ + + }) +}) diff --git a/test/makeChange_test.js b/test/makeChange_test.js index d17098e..d60329d 100644 --- a/test/makeChange_test.js +++ b/test/makeChange_test.js @@ -1,8 +1,10 @@ import { expect } from 'chai' import makeChange from '../src/makeChange' + describe('makeChange()', function(){ + it('should be a function', function(){ expect(makeChange).to.be.a('function') }) diff --git a/test/setComplement_test.js b/test/setComplement_test.js new file mode 100644 index 0000000..a916b8f --- /dev/null +++ b/test/setComplement_test.js @@ -0,0 +1,10 @@ +import { expect } from 'chai' +import setComplement from '../src/setComplement' + + +describe('setComplement()', function(){ + + + it('should be a function', function(){ + expect(setComplement).to.be.a('function') + }) diff --git a/test/setIntersection_test.js b/test/setIntersection_test.js new file mode 100644 index 0000000..8ac24cf --- /dev/null +++ b/test/setIntersection_test.js @@ -0,0 +1,10 @@ +import { expect } from 'chai' +import setintersection from '../src/setIntersection' + + +describe('setIntersection()', function(){ + + + it('should be a function', function(){ + expect(setIntersection).to.be.a('function') + }) diff --git a/test/setSymmetricalDifference_test.js b/test/setSymmetricalDifference_test.js new file mode 100644 index 0000000..2ba4a21 --- /dev/null +++ b/test/setSymmetricalDifference_test.js @@ -0,0 +1,9 @@ +import { expect } from 'chai' +import collatzConjecture from '../src/setSymmetricDifference' + +describe('setSymmetricDifference()', function(){ + + + it('should be a function', function(){ + expect(setSymmetricDifference).to.be.a('function') + }) diff --git a/test/setUnion_test.js b/test/setUnion_test.js new file mode 100644 index 0000000..0481efb --- /dev/null +++ b/test/setUnion_test.js @@ -0,0 +1,8 @@ +import { expect } from 'chai' +import setUnion from '../src/setUnion' + +describe('setUnion', function () { + + it('should be a function'() { + expect((setUnion).to.be.a('function'){ +}