diff --git a/caesar/caesar.js b/caesar/caesar.js index f4d6a25..f70d507 100644 --- a/caesar/caesar.js +++ b/caesar/caesar.js @@ -1,5 +1,22 @@ -const caesar = function() { +const caesar = function (str, num) { + num = num%25; + return str.split('').map(x => { + if(x == ',' + || x == '!' + || x == ' '){return x} + let asciNum = wrap(Number(x.charCodeAt()) + num); + return String.fromCharCode(asciNum) + }).join(''); +} +function wrap(num){ + if (num < 97 && num > 90){ + return num = num%90 + 64; + }else if(num > 122){ + return num = num % 122 + 96; + } else { + return num; + } } module.exports = caesar diff --git a/caesar/caesar.spec.js b/caesar/caesar.spec.js index 49fe254..e0350fc 100644 --- a/caesar/caesar.spec.js +++ b/caesar/caesar.spec.js @@ -4,19 +4,19 @@ describe('caesar', function() { it('works with single letters', function() { expect(caesar('A', 1)).toEqual('B'); }); - xit('works with words', function() { + it('works with words', function() { expect(caesar('Aaa', 1)).toEqual('Bbb'); }); - xit('works with phrases', function() { + it('works with phrases', function() { expect(caesar('Hello, World!', 5)).toEqual('Mjqqt, Btwqi!'); }); xit('works with negative shift', function() { expect(caesar('Mjqqt, Btwqi!', -5)).toEqual('Hello, World!'); }); - xit('wraps', function() { + it('wraps', function() { expect(caesar('Z', 1)).toEqual('A'); }); - xit('works with large shift factors', function() { + it('works with large shift factors', function() { expect(caesar('Hello, World!', 75)).toEqual('Ebiil, Tloia!'); }); xit('works with large negative shift factors', function() { diff --git a/calculator/calculator.js b/calculator/calculator.js index 2d904a8..815c2d5 100644 --- a/calculator/calculator.js +++ b/calculator/calculator.js @@ -1,25 +1,27 @@ -function add () { - +function add (a, b) { + return a+b; } -function subtract () { - +function subtract(a, b) { + return a - b; } -function sum () { - +function sum(arr) { + if (arr.length <1){return 0} + if (arr.length == 1) { return arr[0] } + return arr.reduce((a,b) => a+b); } -function multiply () { - +function multiply(arr) { + return arr.reduce((a, b) => a * b); } -function power() { - +function power(a, b) { + return Math.pow(a, b); } -function factorial() { - +function factorial(a) { + return a < 2 ? 1 : a * factorial(a - 1) } module.exports = { diff --git a/calculator/calculator.spec.js b/calculator/calculator.spec.js index 150a0aa..053b738 100644 --- a/calculator/calculator.spec.js +++ b/calculator/calculator.spec.js @@ -1,77 +1,77 @@ -const calculator = require ('./calculator.js'); +const calculator = require('./calculator.js'); -describe('add', function() { - it('adds 0 and 0', function() { - expect(calculator.add(0,0)).toEqual(0); +describe('add', function () { + it('adds 0 and 0', function () { + expect(calculator.add(0, 0)).toEqual(0); }); - xit('adds 2 and 2', function() { - expect(calculator.add(2,2)).toEqual(4); + it('adds 2 and 2', function () { + expect(calculator.add(2, 2)).toEqual(4); }); - xit('adds positive numbers', function() { - expect(calculator.add(2,6)).toEqual(8); + it('adds positive numbers', function () { + expect(calculator.add(2, 6)).toEqual(8); }); }); -describe('subtract', function() { - xit('subtracts numbers', function() { - expect(calculator.subtract(10,4)).toEqual(6); +describe('subtract', function () { + it('subtracts numbers', function () { + expect(calculator.subtract(10, 4)).toEqual(6); }); }); -describe('sum', function() { - xit('computes the sum of an empty array', function() { +describe('sum', function () { + it('computes the sum of an empty array', function () { expect(calculator.sum([])).toEqual(0); }); - xit('computes the sum of an array of one number', function() { + it('computes the sum of an array of one number', function () { expect(calculator.sum([7])).toEqual(7); }); - xit('computes the sum of an array of two numbers', function() { - expect(calculator.sum([7,11])).toEqual(18); + it('computes the sum of an array of two numbers', function () { + expect(calculator.sum([7, 11])).toEqual(18); }); - xit('computes the sum of an array of many numbers', function() { - expect(calculator.sum([1,3,5,7,9])).toEqual(25); + it('computes the sum of an array of many numbers', function () { + expect(calculator.sum([1, 3, 5, 7, 9])).toEqual(25); }); }); -describe('multiply', function() { - xit('multiplies two numbers', function() { - expect(calculator.multiply([2,4])).toEqual(8); +describe('multiply', function () { + it('multiplies two numbers', function () { + expect(calculator.multiply([2, 4])).toEqual(8); }); - xit('multiplies several numbers', function() { - expect(calculator.multiply([2,4,6,8,10,12,14])).toEqual(645120); + it('multiplies several numbers', function () { + expect(calculator.multiply([2, 4, 6, 8, 10, 12, 14])).toEqual(645120); }); }); -describe('power', function() { - xit('raises one number to the power of another number', function() { - expect(calculator.power(4,3)).toEqual(64); // 4 to third power is 64 +describe('power', function () { + it('raises one number to the power of another number', function () { + expect(calculator.power(4, 3)).toEqual(64); // 4 to third power is 64 }); }); -describe('factorial', function() { - xit('computes the factorial of 0', function() { +describe('factorial', function () { + it('computes the factorial of 0', function () { expect(calculator.factorial(0)).toEqual(1); // 0! = 1 }); - xit('computes the factorial of 1', function() { + it('computes the factorial of 1', function () { expect(calculator.factorial(1)).toEqual(1); }); - xit('computes the factorial of 2', function() { + it('computes the factorial of 2', function () { expect(calculator.factorial(2)).toEqual(2); }); - xit('computes the factorial of 5', function() { + it('computes the factorial of 5', function () { expect(calculator.factorial(5)).toEqual(120); }); - xit('computes the factorial of 10', function() { + it('computes the factorial of 10', function () { expect(calculator.factorial(10)).toEqual(3628800); }); }); diff --git a/fibonacci/fibonacci.js b/fibonacci/fibonacci.js index fd597f9..a45d688 100644 --- a/fibonacci/fibonacci.js +++ b/fibonacci/fibonacci.js @@ -1,5 +1,12 @@ -const fibonacci = function() { - +const fibonacci = function (num) { + if (num < 0) { return "OOPS"} + let sum = []; + sum[0] = 0; + sum[1] = 1; + for (let i = 2; i <= num; i++) { + sum[i] = sum[i - 1] + sum[i - 2]; + } + return sum[num]; } module.exports = fibonacci diff --git a/fibonacci/fibonacci.spec.js b/fibonacci/fibonacci.spec.js index cafe796..9f9d19d 100644 --- a/fibonacci/fibonacci.spec.js +++ b/fibonacci/fibonacci.spec.js @@ -4,28 +4,28 @@ describe('fibonacci', function() { it('works', function() { expect(fibonacci(4)).toEqual(3); }); - xit('works', function() { + it('works', function() { expect(fibonacci(6)).toEqual(8); }); - xit('works', function() { + it('works', function() { expect(fibonacci(10)).toEqual(55); }); - xit('works', function() { + it('works', function() { expect(fibonacci(15)).toEqual(610); }); - xit('works', function() { + it('works', function() { expect(fibonacci(25)).toEqual(75025); }); - xit('doesn\'t accept negatives', function() { + it('doesn\'t accept negatives', function() { expect(fibonacci(-25)).toEqual("OOPS"); }); - xit('DOES accept strings', function() { + it('DOES accept strings', function() { expect(fibonacci("1")).toEqual(1); }); - xit('DOES accept strings', function() { + it('DOES accept strings', function() { expect(fibonacci("2")).toEqual(1); }); - xit('DOES accept strings', function() { + it('DOES accept strings', function() { expect(fibonacci("8")).toEqual(21); }); }); diff --git a/findTheOldest/findTheOldest.js b/findTheOldest/findTheOldest.js index b91dfe0..6015c10 100644 --- a/findTheOldest/findTheOldest.js +++ b/findTheOldest/findTheOldest.js @@ -1,5 +1,20 @@ -let findTheOldest = function() { - +let findTheOldest = function (arr) { + let biggest = -Infinity; + let age; + let oldest = {name: ''}; + arr.map(x => { + if (x.yearOfDeath === undefined) { + age = 2020 - x.yearOfBirth + } else { + age = x.yearOfDeath - x.yearOfBirth + } + if (age > biggest) { + biggest = age; + oldest.name = x.name; + return biggest; + } + }); + return oldest; } module.exports = findTheOldest diff --git a/findTheOldest/findTheOldest.spec.js b/findTheOldest/findTheOldest.spec.js index f7b2ad1..69e6da0 100644 --- a/findTheOldest/findTheOldest.spec.js +++ b/findTheOldest/findTheOldest.spec.js @@ -21,7 +21,7 @@ describe('findTheOldest', function() { ] expect(findTheOldest(people).name).toEqual('Ray'); }); - xit('finds the oldest person if someone is still living', function() { + it('finds the oldest person if someone is still living', function() { const people = [ { name: 'Carly', @@ -40,7 +40,7 @@ describe('findTheOldest', function() { ] expect(findTheOldest(people).name).toEqual('Ray'); }); - xit('finds the oldest person if the OLDEST is still living', function() { + it('finds the oldest person if the OLDEST is still living', function() { const people = [ { name: 'Carly', diff --git a/getTheTitles/getTheTitles.js b/getTheTitles/getTheTitles.js index 2b52aa0..22ad099 100644 --- a/getTheTitles/getTheTitles.js +++ b/getTheTitles/getTheTitles.js @@ -1,5 +1,9 @@ -const getTheTitles = function() { - +const getTheTitles = function(arr) { + let newArr = []; + arr.map(x=> { + newArr.push(x.title) + }); + return newArr; } module.exports = getTheTitles; diff --git a/helloWorld/helloWorld.js b/helloWorld/helloWorld.js index a41264d..7d01115 100644 --- a/helloWorld/helloWorld.js +++ b/helloWorld/helloWorld.js @@ -1,5 +1,5 @@ const helloWorld = function() { - return '' + return 'Hello, World!' } module.exports = helloWorld diff --git a/leapYears/leapYears.js b/leapYears/leapYears.js index ac786a2..6ad487d 100644 --- a/leapYears/leapYears.js +++ b/leapYears/leapYears.js @@ -1,5 +1,16 @@ -const leapYears = function() { - +const leapYears = function(year) { + if(year%100 == 0){ + if ((year / 100) % 4 == 0) { + return true; + } else { + return false; + } + } + if ( year%4 == 0){ + return true; + }else { + return false; + } } module.exports = leapYears diff --git a/leapYears/leapYears.spec.js b/leapYears/leapYears.spec.js index 0d4d7d4..f4cdea8 100644 --- a/leapYears/leapYears.spec.js +++ b/leapYears/leapYears.spec.js @@ -4,19 +4,19 @@ describe('leapYears', function() { it('works with non century years', function() { expect(leapYears(1996)).toEqual(true); }); - xit('works with non century years', function() { + it('works with non century years', function() { expect(leapYears(1997)).toEqual(false); }); - xit('works with ridiculously futuristic non century years', function() { + it('works with ridiculously futuristic non century years', function() { expect(leapYears(34992)).toEqual(true); }); - xit('works with century years', function() { + it('works with century years', function() { expect(leapYears(1900)).toEqual(false); }); - xit('works with century years', function() { + it('works with century years', function() { expect(leapYears(1600)).toEqual(true); }); - xit('works with century years', function() { + it('works with century years', function() { expect(leapYears(700)).toEqual(false); }); }); diff --git a/removeFromArray/removeFromArray.js b/removeFromArray/removeFromArray.js index 11efd5c..c738289 100644 --- a/removeFromArray/removeFromArray.js +++ b/removeFromArray/removeFromArray.js @@ -1,5 +1,10 @@ -const removeFromArray = function() { - +const removeFromArray = function (arr, ...indx) { + indx.map(x => { + if (arr.indexOf(x) == -1){ return x} + arr.splice(arr.indexOf(x), 1); + }) + + return arr; } module.exports = removeFromArray diff --git a/removeFromArray/removeFromArray.spec.js b/removeFromArray/removeFromArray.spec.js index 28c744c..6185342 100644 --- a/removeFromArray/removeFromArray.spec.js +++ b/removeFromArray/removeFromArray.spec.js @@ -4,19 +4,19 @@ describe('removeFromArray', function() { it('removes a single value', function() { expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]); }); - xit('removes multiple values', function() { + it('removes multiple values', function() { expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]); }); - xit('ignores non present values', function() { + it('ignores non present values', function() { expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]); }); - xit('ignores non present values, but still works', function() { + it('ignores non present values, but still works', function() { expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]); }); - xit('can remove all values', function() { + it('can remove all values', function() { expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]); }); - xit('works with strings', function() { + it('works with strings', function() { expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]); }); }); diff --git a/repeatString/repeatString.js b/repeatString/repeatString.js index 770119a..91f7384 100644 --- a/repeatString/repeatString.js +++ b/repeatString/repeatString.js @@ -1,5 +1,6 @@ -const repeatString = function() { - +const repeatString = function(str, num) { + if (num < 0) { return 'ERROR'}; + return str.repeat(num); } module.exports = repeatString diff --git a/repeatString/repeatString.spec.js b/repeatString/repeatString.spec.js index 931b437..e27a686 100644 --- a/repeatString/repeatString.spec.js +++ b/repeatString/repeatString.spec.js @@ -4,16 +4,16 @@ describe('repeatString', function() { it('repeats the string', function() { expect(repeatString('hey', 3)).toEqual('heyheyhey'); }); - xit('repeats the string many times', function() { + it('repeats the string many times', function() { expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey'); }); - xit('repeats the string 1 times', function() { + it('repeats the string 1 times', function() { expect(repeatString('hey', 1)).toEqual('hey'); }); - xit('repeats the string 0 times', function() { + it('repeats the string 0 times', function() { expect(repeatString('hey', 0)).toEqual(''); }); - xit('returns ERROR with negative numbers', function() { + it('returns ERROR with negative numbers', function() { expect(repeatString('hey', -1)).toEqual('ERROR'); }); }); diff --git a/reverseString/reverseString.js b/reverseString/reverseString.js index febb577..e9da1ea 100644 --- a/reverseString/reverseString.js +++ b/reverseString/reverseString.js @@ -1,5 +1,5 @@ -const reverseString = function() { - +const reverseString = function(str) { + return str.split('').reverse().join(''); } module.exports = reverseString diff --git a/reverseString/reverseString.spec.js b/reverseString/reverseString.spec.js index e48840c..a7a543e 100644 --- a/reverseString/reverseString.spec.js +++ b/reverseString/reverseString.spec.js @@ -5,11 +5,11 @@ describe('reverseString', function() { expect(reverseString('hello')).toEqual('olleh'); }); - xit('reverses multiple words', function() { + it('reverses multiple words', function() { expect(reverseString('hello there')).toEqual('ereht olleh') }) - xit('works with numbers and punctuation', function() { + it('works with numbers and punctuation', function() { expect(reverseString('123! abc!')).toEqual('!cba !321') }) }); diff --git a/sumAll/sumAll.js b/sumAll/sumAll.js index 4030fe8..63a1390 100644 --- a/sumAll/sumAll.js +++ b/sumAll/sumAll.js @@ -1,5 +1,14 @@ -const sumAll = function() { - +const sumAll = function (first, last) { + if (first < 0) { return 'ERROR' } + if (typeof first !== 'number' || typeof last !== 'number') { return 'ERROR' } + first = Number(first); + last = Number(last); + let arr = [first,last].sort(); + let sum = 0; + for (arr[0]; arr[0] <= arr[1]; arr[0]++) { + sum = Number(sum) + arr[0] + } + return sum; } module.exports = sumAll diff --git a/sumAll/sumAll.spec.js b/sumAll/sumAll.spec.js index 520adc1..2a584a6 100644 --- a/sumAll/sumAll.spec.js +++ b/sumAll/sumAll.spec.js @@ -4,19 +4,19 @@ describe('sumAll', function() { it('sums numbers within the range', function() { expect(sumAll(1, 4)).toEqual(10); }); - xit('works with large numbers', function() { + it('works with large numbers', function() { expect(sumAll(1, 4000)).toEqual(8002000); }); - xit('works with larger number first', function() { + it('works with larger number first', function() { expect(sumAll(123, 1)).toEqual(7626); }); - xit('returns ERROR with negative numbers', function() { + it('returns ERROR with negative numbers', function() { expect(sumAll(-10, 4)).toEqual('ERROR'); }); - xit('returns ERROR with non-number parameters', function() { + it('returns ERROR with non-number parameters', function() { expect(sumAll(10, "90")).toEqual('ERROR'); }); - xit('returns ERROR with non-number parameters', function() { + it('returns ERROR with non-number parameters', function() { expect(sumAll(10, [90, 1])).toEqual('ERROR'); }); });