From f7ac5a2f92b55e6fa9148c84d874315f14c17bea Mon Sep 17 00:00:00 2001 From: Don Date: Thu, 28 Jul 2022 11:21:24 -0400 Subject: [PATCH] Completed palindromes and fibonacci exercises --- 09_palindromes/palindromes.js | 10 ++++++++-- 09_palindromes/palindromes.spec.js | 10 +++++----- 10_fibonacci/fibonacci.js | 21 ++++++++++++++++++++- 10_fibonacci/fibonacci.spec.js | 16 ++++++++-------- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/09_palindromes/palindromes.js b/09_palindromes/palindromes.js index 8d21018..6fead83 100644 --- a/09_palindromes/palindromes.js +++ b/09_palindromes/palindromes.js @@ -1,6 +1,12 @@ -const palindromes = function () { - +const palindromes = function (myString) { + const strippedString = myString.replace(/[^a-z0-9]/gi, '').toUpperCase(); + const reversedString = strippedString.split("").reverse().join("").toUpperCase(); +// console.log(strippedString) +// console.log(reversedString) + return strippedString === reversedString ? true: false; }; +palindromes("racecar!") + // Do not edit below this line module.exports = palindromes; diff --git a/09_palindromes/palindromes.spec.js b/09_palindromes/palindromes.spec.js index 6e14ed1..1b0cd5e 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 maracaz.')).toBe(false); }); }); diff --git a/10_fibonacci/fibonacci.js b/10_fibonacci/fibonacci.js index bb2c8cc..e428f72 100644 --- a/10_fibonacci/fibonacci.js +++ b/10_fibonacci/fibonacci.js @@ -1,6 +1,25 @@ -const fibonacci = function() { +const fibonacci = function(fibLength) { + if (fibLength < 0) { + return "OOPS"; + } + + if (fibLength === 0) { + return 0; + } + + let valueA = 0; + let valueB = 1; + + for (i = 1; i < fibLength; i++) { + let tempValue = valueB; + valueB += valueA; + valueA = tempValue; + } + return valueB; }; +fibonacci('1') + // Do not edit below this line module.exports = fibonacci; 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); }); });