From e6e4540b32b835257135d62c1d037cc9630c3104 Mon Sep 17 00:00:00 2001 From: BananaBJones Date: Wed, 24 Nov 2021 15:37:27 -0700 Subject: [PATCH] m --- 03_reverseString/reverseString.js | 4 +-- 06_leapYears/leapYears.js | 9 ++++- 06_leapYears/leapYears.spec.js | 11 +++--- 07_tempConversion/tempConversion.js | 12 ++++--- 07_tempConversion/tempConversion.spec.js | 10 +++--- 08_calculator/calculator.js | 46 ++++++++++++++++++------ 08_calculator/calculator.spec.js | 30 ++++++++-------- 09_palindromes/palindromes.js | 17 +++++++-- 09_palindromes/palindromes.spec.js | 10 +++--- 10_fibonacci/delete | 5 +++ 10_fibonacci/delete.js | 5 +++ 10_fibonacci/fibonacci.js | 12 +++++-- 10_fibonacci/fibonacci.spec.js | 16 ++++----- 11_getTheTitles/getTheTitles.js | 8 +++-- 12_findTheOldest/README.md | 5 +++ 12_findTheOldest/findTheOldest.js | 3 +- 13_caesar/caesar.js | 15 +++++++- 13_caesar/caesar.spec.js | 4 +-- 18 files changed, 156 insertions(+), 66 deletions(-) create mode 100644 10_fibonacci/delete create mode 100644 10_fibonacci/delete.js diff --git a/03_reverseString/reverseString.js b/03_reverseString/reverseString.js index a9e3d67..699f890 100644 --- a/03_reverseString/reverseString.js +++ b/03_reverseString/reverseString.js @@ -1,6 +1,6 @@ const reverseString = function(str) { - var newString = ''; - for (i = str.length -1; i >=0; i--) { + let newString = ''; + for (i = str.length -1; i>=0; i--) { newString += str[i]; } return newString; diff --git a/06_leapYears/leapYears.js b/06_leapYears/leapYears.js index 681eeef..17b4cac 100644 --- a/06_leapYears/leapYears.js +++ b/06_leapYears/leapYears.js @@ -1,4 +1,11 @@ -const leapYears = function() { +const leapYears = function(year) { + if ( year % 100 === 0 && year % 400 != 0) { + return false; + } else if ( year % 4 === 0|| year % 400 === 0) { + return true; + } else { + return false; + } }; diff --git a/06_leapYears/leapYears.spec.js b/06_leapYears/leapYears.spec.js index 6fdaba9..ad2feb5 100644 --- a/06_leapYears/leapYears.spec.js +++ b/06_leapYears/leapYears.spec.js @@ -4,19 +4,20 @@ describe('leapYears', () => { test('works with non century years', () => { expect(leapYears(1996)).toBe(true); }); - test.skip('works with non century years', () => { + test('works with non century years', () => { expect(leapYears(1997)).toBe(false); }); - test.skip('works with ridiculously futuristic non century years', () => { + test('works with ridiculously futuristic non century years', () => { expect(leapYears(34992)).toBe(true); }); - test.skip('works with century years', () => { + test('works with century years', () => { expect(leapYears(1900)).toBe(false); }); - test.skip('works with century years', () => { + test('works with century years', () => { expect(leapYears(1600)).toBe(true); }); - test.skip('works with century years', () => { + test('works with century years', () => { expect(leapYears(700)).toBe(false); }); + }); diff --git a/07_tempConversion/tempConversion.js b/07_tempConversion/tempConversion.js index 6ef3e85..db90fec 100644 --- a/07_tempConversion/tempConversion.js +++ b/07_tempConversion/tempConversion.js @@ -1,9 +1,13 @@ -const ftoc = function() { - +const ftoc = function(f) { + c = (f - 32) * (5/9); + let rounded = Math.round(c * 10) / 10; + return rounded; }; -const ctof = function() { - +const ctof = function(c) { + f = (c * (9/5) + 32); + let rounded = Math.round(f * 10) / 10; + return rounded; }; // Do not edit below this line diff --git a/07_tempConversion/tempConversion.spec.js b/07_tempConversion/tempConversion.spec.js index 93679cc..b1b82f2 100644 --- a/07_tempConversion/tempConversion.spec.js +++ b/07_tempConversion/tempConversion.spec.js @@ -4,22 +4,22 @@ describe('ftoc', () => { test('works', () => { expect(ftoc(32)).toEqual(0); }); - test.skip('rounds to 1 decimal', () => { + test('rounds to 1 decimal', () => { expect(ftoc(100)).toEqual(37.8); }); - test.skip('works with negatives', () => { + test('works with negatives', () => { expect(ftoc(-100)).toEqual(-73.3); }); }); describe('ctof', () => { - test.skip('works', () => { + test('works', () => { expect(ctof(0)).toEqual(32); }); - test.skip('rounds to 1 decimal', () => { + test('rounds to 1 decimal', () => { expect(ctof(73.2)).toEqual(163.8); }); - test.skip('works with negatives', () => { + test('works with negatives', () => { expect(ctof(-10)).toEqual(14); }); }); diff --git a/08_calculator/calculator.js b/08_calculator/calculator.js index c22e8d2..f4e776f 100644 --- a/08_calculator/calculator.js +++ b/08_calculator/calculator.js @@ -1,25 +1,49 @@ -const add = function() { - +const add = function(num1, num2) { + let sum = num1 + num2; + return sum; }; -const subtract = function() { - +const subtract = function(num1, num2) { + let sum = num1 - num2; + return sum; }; -const sum = function() { - +const sum = function(array) { + let sum = 0; + if (array.length > 0) { + for (i = 0; i < array.length; i++ ) { + sum += array[i]; + } + } else { + let sum = 0; + return sum; + } + return sum; }; -const multiply = function() { +const multiply = function(array) { + let sum = 1; + for (i = 0; i < array.length; i++) { + sum = sum * array[i]; + } + return sum; }; -const power = function() { - +const power = function(num1, num2) { + let sum = 1; + for (i = 0; i < num2; i++) { + sum = sum * num1; + } + return sum; }; -const factorial = function() { - +const factorial = function(num) { + let sum = 1; + for (i = num; i > 0; i--) { + sum = sum * i; + } + return sum; }; // Do not edit below this line diff --git a/08_calculator/calculator.spec.js b/08_calculator/calculator.spec.js index dc317ec..c82a04b 100644 --- a/08_calculator/calculator.spec.js +++ b/08_calculator/calculator.spec.js @@ -5,73 +5,73 @@ describe('add', () => { expect(calculator.add(0,0)).toBe(0); }); - test.skip('adds 2 and 2', () => { + test('adds 2 and 2', () => { expect(calculator.add(2,2)).toBe(4); }); - test.skip('adds positive numbers', () => { + test('adds positive numbers', () => { expect(calculator.add(2,6)).toBe(8); }); }); describe('subtract', () => { - test.skip('subtracts numbers', () => { + test('subtracts numbers', () => { expect(calculator.subtract(10,4)).toBe(6); }); }); describe('sum', () => { - test.skip('computes the sum of an empty array', () => { + test('computes the sum of an empty array', () => { expect(calculator.sum([])).toBe(0); }); - test.skip('computes the sum of an array of one number', () => { + test('computes the sum of an array of one number', () => { expect(calculator.sum([7])).toBe(7); }); - test.skip('computes the sum of an array of two numbers', () => { + test('computes the sum of an array of two numbers', () => { expect(calculator.sum([7,11])).toBe(18); }); - test.skip('computes the sum of an array of many numbers', () => { + test('computes the sum of an array of many numbers', () => { expect(calculator.sum([1,3,5,7,9])).toBe(25); }); }); describe('multiply', () => { - test.skip('multiplies two numbers', () => { + test('multiplies two numbers', () => { expect(calculator.multiply([2,4])).toBe(8); }); - test.skip('multiplies several numbers', () => { + test('multiplies several numbers', () => { expect(calculator.multiply([2,4,6,8,10,12,14])).toBe(645120); }); }); describe('power', () => { - test.skip('raises one number to the power of another number', () => { + test('raises one number to the power of another number', () => { expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64 }); }); describe('factorial', () => { - test.skip('computes the factorial of 0', () => { + test('computes the factorial of 0', () => { expect(calculator.factorial(0)).toBe(1); // 0! = 1 }); - test.skip('computes the factorial of 1', () => { + test('computes the factorial of 1', () => { expect(calculator.factorial(1)).toBe(1); }); - test.skip('computes the factorial of 2', () => { + test('computes the factorial of 2', () => { expect(calculator.factorial(2)).toBe(2); }); - test.skip('computes the factorial of 5', () => { + test('computes the factorial of 5', () => { expect(calculator.factorial(5)).toBe(120); }); - test.skip('computes the factorial of 10', () => { + test('computes the factorial of 10', () => { expect(calculator.factorial(10)).toBe(3628800); }); }); diff --git a/09_palindromes/palindromes.js b/09_palindromes/palindromes.js index 8d21018..5ebe27c 100644 --- a/09_palindromes/palindromes.js +++ b/09_palindromes/palindromes.js @@ -1,5 +1,18 @@ -const palindromes = function () { - +const palindromes = function (string) { + let newString = ''; + // strip string of all puncuation and whitespace + let cleanString = string.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()\s+]/g, ''); + cleanString = cleanString.toLowerCase(); + // reverse string + for (i = cleanString.length - 1; i>=0; i--) { + newString += cleanString[i]; + } + // check if palindrome + if (newString === cleanString) { + return true; + } else { + return false; + } }; // Do not edit below this line diff --git a/09_palindromes/palindromes.spec.js b/09_palindromes/palindromes.spec.js index 2f239d3..0936437 100644 --- a/09_palindromes/palindromes.spec.js +++ b/09_palindromes/palindromes.spec.js @@ -4,19 +4,19 @@ describe('palindromes', () => { test('works with single words', () => { expect(palindromes('racecar')).toBe(true); }); - test.skip('works with punctuation ', () => { + test('works with punctuation ', () => { expect(palindromes('racecar!')).toBe(true); }); - test.skip('works with upper-case letters ', () => { + test('works with upper-case letters ', () => { expect(palindromes('Racecar!')).toBe(true); }); - test.skip('works with multiple words', () => { + test('works with multiple words', () => { expect(palindromes('A car, a man, a maraca.')).toBe(true); }); - test.skip('works with multiple words', () => { + test('works with multiple words', () => { expect(palindromes('Animal loots foliated detail of stool lamina.')).toBe(true); }); - test.skip('doesn\'t just always return true', () => { + test('doesn\'t just always return true', () => { expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false); }); }); diff --git a/10_fibonacci/delete b/10_fibonacci/delete new file mode 100644 index 0000000..1c21e29 --- /dev/null +++ b/10_fibonacci/delete @@ -0,0 +1,5 @@ +const outerArr = []; +const innerArr = []; +// outerArr.push(innerArr); +innerArr[0] = "hello"; +console.log(outerArr); diff --git a/10_fibonacci/delete.js b/10_fibonacci/delete.js new file mode 100644 index 0000000..59285a8 --- /dev/null +++ b/10_fibonacci/delete.js @@ -0,0 +1,5 @@ +const outerArr = []; +const innerArr = []; +outerArr.push(innerArr); +innerArr[0] = "hello"; +console.log(outerArr); diff --git a/10_fibonacci/fibonacci.js b/10_fibonacci/fibonacci.js index bb2c8cc..01f5642 100644 --- a/10_fibonacci/fibonacci.js +++ b/10_fibonacci/fibonacci.js @@ -1,5 +1,13 @@ -const fibonacci = function() { - +const fibonacci = function(Fn) { + let fib = [0, 1]; + if (Fn >= 0) { + for (i=2;i<=Fn;i++) { + fib[i] = fib[i-2] + fib[i-1]; + } + } else { + return 'OOPS' + } + return fib[Fn]; }; // Do not edit below this line diff --git a/10_fibonacci/fibonacci.spec.js b/10_fibonacci/fibonacci.spec.js index 7f62213..32f38ee 100644 --- a/10_fibonacci/fibonacci.spec.js +++ b/10_fibonacci/fibonacci.spec.js @@ -4,28 +4,28 @@ describe('fibonacci', () => { test('4th fibonacci number is 3', () => { expect(fibonacci(4)).toBe(3); }); - test.skip('6th fibonacci number is 8', () => { + test('6th fibonacci number is 8', () => { expect(fibonacci(6)).toBe(8); }); - test.skip('10th fibonacci number is 55', () => { + test('10th fibonacci number is 55', () => { expect(fibonacci(10)).toBe(55); }); - test.skip('15th fibonacci number is 610', () => { + test('15th fibonacci number is 610', () => { expect(fibonacci(15)).toBe(610); }); - test.skip('25th fibonacci number is 75025', () => { + test('25th fibonacci number is 75025', () => { expect(fibonacci(25)).toBe(75025); }); - test.skip('doesn\'t accept negatives', () => { + test('doesn\'t accept negatives', () => { expect(fibonacci(-25)).toBe("OOPS"); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(fibonacci("1")).toBe(1); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(fibonacci("2")).toBe(1); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(fibonacci("8")).toBe(21); }); }); diff --git a/11_getTheTitles/getTheTitles.js b/11_getTheTitles/getTheTitles.js index 74b04df..4f64f08 100644 --- a/11_getTheTitles/getTheTitles.js +++ b/11_getTheTitles/getTheTitles.js @@ -1,5 +1,9 @@ -const getTheTitles = function() { - +const getTheTitles = function(array) { + let titles = []; + for (i=0;i= 65 && uniNum <= 90 || uniNum >= 97 && uniNum <= 122) { + shiftedNum = uniNum + offSet ; // Shift unicode + shiftedString += String.fromCharCode(shiftedNum); // Converts back to character + } else { + shiftedString += string[i]; // Change Nothing + } + } + return shiftedString; }; // Do not edit below this line diff --git a/13_caesar/caesar.spec.js b/13_caesar/caesar.spec.js index 3ff9a35..217d14b 100644 --- a/13_caesar/caesar.spec.js +++ b/13_caesar/caesar.spec.js @@ -3,10 +3,10 @@ const caesar = require('./caesar') test('works with single letters', () => { expect(caesar('A', 1)).toBe('B'); }); -test.skip('works with words', () => { +test('works with words', () => { expect(caesar('Aaa', 1)).toBe('Bbb'); }); -test.skip('works with phrases', () => { +test('works with phrases', () => { expect(caesar('Hello, World!', 5)).toBe('Mjqqt, Btwqi!'); }); test.skip('works with negative shift', () => {