Completed palindromes and fibonacci exercises
This commit is contained in:
parent
def13a957b
commit
f7ac5a2f92
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue