Merge pull request #15856 from AungMyoKyaw/feat/eluer-prob-4
feat(euler-problem): Add tests and solution for Problem 4: Largest palindrome product
This commit is contained in:
@ -94,17 +94,20 @@
|
|||||||
"type": "bonfire",
|
"type": "bonfire",
|
||||||
"title": "Problem 4: Largest palindrome product",
|
"title": "Problem 4: Largest palindrome product",
|
||||||
"tests": [
|
"tests": [
|
||||||
"assert.strictEqual(euler4(), 906609, 'message: <code>euler4()</code> should return 906609.');"
|
"assert.strictEqual(largestPalindromeProduct(2), 9009, 'message: <code>largestPalindromeProduct(2)</code> should return 9009.');",
|
||||||
|
"assert.strictEqual(largestPalindromeProduct(3), 906609, 'message: <code>largestPalindromeProduct(3)</code> should return 906609.');"
|
||||||
|
],
|
||||||
|
"solutions": [
|
||||||
|
"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 = /\\b(\\d)(\\d?)(\\d?).?\\3\\2\\1\\b/gi;\n palindromeRegex.test(product) && palindrome.push(product);\n }\n }\n return Math.max(...palindrome);\n}"
|
||||||
],
|
],
|
||||||
"solutions": [],
|
|
||||||
"translations": {},
|
"translations": {},
|
||||||
"challengeSeed": [
|
"challengeSeed": [
|
||||||
"function euler4() {",
|
"function largestPalindromeProduct(digit) {",
|
||||||
" // Good luck!",
|
" // Good luck!",
|
||||||
" return true;",
|
" return true;",
|
||||||
"}",
|
"}",
|
||||||
"",
|
"",
|
||||||
"euler4();"
|
"largestPalindromeProduct(3);"
|
||||||
],
|
],
|
||||||
"description": [
|
"description": [
|
||||||
"A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.",
|
"A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.",
|
||||||
|
@ -215,10 +215,12 @@ Observable.from(getChallenges())
|
|||||||
.toArray()
|
.toArray()
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(noSolutions) => {
|
(noSolutions) => {
|
||||||
console.log(
|
if(noSolutions){
|
||||||
'# These challenges have no solutions\n- [ ] ' +
|
console.log(
|
||||||
noSolutions.join('\n- [ ] ')
|
'# These challenges have no solutions\n- [ ] ' +
|
||||||
);
|
noSolutions.join('\n- [ ] ')
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
err => { throw err; },
|
err => { throw err; },
|
||||||
() => process.exit(0)
|
() => process.exit(0)
|
||||||
|
Reference in New Issue
Block a user