Skip to content

Commit 25013df

Browse files
authored
Merge pull request #357 from marlatte/fibonacci_palindromes_fixes
09_palindrome and 10_fibonacci: Update solutions
2 parents 8692f0e + fd1e1f9 commit 25013df

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

09_palindromes/palindromes.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ describe('palindromes', () => {
2222
test.skip('works with numbers in a string', () => {
2323
expect(palindromes('rac3e3car')).toBe(true);
2424
});
25+
test.skip('works with unevenly spaced numbers in a string', () => {
26+
expect(palindromes('r3ace3car')).toBe(false);
27+
});
2528
});

09_palindromes/solution/palindromes-solution.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const palindromes = function (string) {
2-
const processedString = string.toLowerCase().replace(/[^a-z]/g, "");
2+
const processedString = string.toLowerCase().replace(/[^a-z0-9]/g, "");
33
return processedString.split("").reverse().join("") == processedString;
44
};
55

09_palindromes/solution/palindromes-solution.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ describe('palindromes', () => {
2424
test('works with numbers in a string', () => {
2525
expect(palindromes('rac3e3car')).toBe(true);
2626
});
27+
test('works with unevenly spaced numbers in a string', () => {
28+
expect(palindromes('r3ace3car')).toBe(false);
29+
});
2730
});
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
const fibonacci = function (count) {
2-
if (count < 0) return "OOPS";
3-
if (count === 0) return 0;
4-
let a = 0;
5-
let b = 1;
6-
for (let i = 1; i < count; i++) {
7-
const temp = b;
8-
b = a + b;
9-
a = temp;
10-
}
11-
return b;
1+
const fibonacci = function(count) {
2+
if (count < 0) return "OOPS"
3+
const fibPart = [0, 1];
4+
for (let index = 1; index < count; index++) {
5+
fibPart.push(fibPart[index] + fibPart[index -1]);
6+
}
7+
return fibPart[count];
128
};
139

1410
module.exports = fibonacci;

10_fibonacci/solution/fibonacci-solution.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ describe('fibonacci', () => {
1616
test('25th fibonacci number is 75025', () => {
1717
expect(fibonacci(25)).toBe(75025);
1818
});
19+
test('0th fibonacci number is o', () => {
20+
expect(fibonacci(0)).toBe(0);
21+
});
1922
test("doesn't accept negatives", () => {
2023
expect(fibonacci(-25)).toBe('OOPS');
2124
});

0 commit comments

Comments
 (0)