diff --git a/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json b/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json index 64ee1af438..b0a125d8a1 100644 --- a/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json +++ b/challenges/08-coding-interview-questions-and-take-home-assignments/project-euler-problems.json @@ -94,17 +94,20 @@ "type": "bonfire", "title": "Problem 4: Largest palindrome product", "tests": [ - "assert.strictEqual(euler4(), 906609, 'message: euler4() should return 906609.');" + "assert.strictEqual(largestPalindromeProduct(2), 9009, 'message: largestPalindromeProduct(2) should return 9009.');", + "assert.strictEqual(largestPalindromeProduct(3), 906609, 'message: largestPalindromeProduct(3) 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": {}, "challengeSeed": [ - "function euler4() {", + "function largestPalindromeProduct(digit) {", " // Good luck!", " return true;", "}", "", - "euler4();" + "largestPalindromeProduct(3);" ], "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.", diff --git a/test-challenges.js b/test-challenges.js index eb628a991e..b645f0a71c 100644 --- a/test-challenges.js +++ b/test-challenges.js @@ -215,10 +215,12 @@ Observable.from(getChallenges()) .toArray() .subscribe( (noSolutions) => { - console.log( - '# These challenges have no solutions\n- [ ] ' + - noSolutions.join('\n- [ ] ') - ); + if(noSolutions){ + console.log( + '# These challenges have no solutions\n- [ ] ' + + noSolutions.join('\n- [ ] ') + ); + } }, err => { throw err; }, () => process.exit(0)