Skip to content

Commit 5ec8341

Browse files
committed
feat(euler-problem): Add tests and solution for Problem 4: Largest palindrome product
1 parent 4aa4248 commit 5ec8341

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

seed/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,20 @@
9494
"type": "bonfire",
9595
"title": "Problem 4: Largest palindrome product",
9696
"tests": [
97-
"assert.strictEqual(euler4(), 906609, 'message: <code>euler4()</code> should return 906609.');"
97+
"assert.strictEqual(largestPalindromeProduct(2), 9009, 'message: <code>largestPalindromeProduct(2)</code> should return 9009.');",
98+
"assert.strictEqual(largestPalindromeProduct(3), 906609, 'message: <code>largestPalindromeProduct(3)</code> should return 906609.');"
99+
],
100+
"solutions": [
101+
"const largestPalindromeProduct = (digit)=>{\n let start = 1;\n let end = Number(`1e${digit}`) - 1;\n let palindrome = [];\n for(let i=start;i<=end;i++){\n for(let j=start;j<=end;j++){\n let product = i*j;\n let palindromeRegex = new RegExp('\\b(\\d)(\\d?)(\\d?).?\\3\\2\\1\\b','gi');\n palindromeRegex.test(product) && palindrome.push(product);\n }\n }\n return Math.max(...palindrome);\n}"
98102
],
99-
"solutions": [],
100103
"translations": {},
101104
"challengeSeed": [
102-
"function euler4() {",
105+
"function largestPalindromeProduct(digit) {",
103106
" // Good luck!",
104107
" return true;",
105108
"}",
106109
"",
107-
"euler4();"
110+
"largestPalindromeProduct(3);"
108111
],
109112
"description": [
110113
"A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.",

0 commit comments

Comments
 (0)