fix(challenges): Add tests and solution for Euler problem 5 (#16421)

pull/18182/head
Kristofer Koishigawa 2018-01-15 15:06:42 +09:00 committed by mrugesh mohapatra
parent 3c266b2663
commit c79068e058
1 changed files with 6 additions and 4 deletions

View File

@ -117,17 +117,19 @@
"type": "bonfire", "type": "bonfire",
"title": "Problem 5: Smallest multiple", "title": "Problem 5: Smallest multiple",
"tests": [ "tests": [
"assert.strictEqual(euler5(), 232792560, 'message: <code>euler5()</code> should return 232792560.');" "assert.strictEqual(smallestMult(5), 60, 'message: <code>smallestMult(5)</code> should return 60.');",
"assert.strictEqual(smallestMult(10), 2520, 'message: <code>smallestMult(10)</code> should return 2520.');",
"assert.strictEqual(smallestMult(20), 232792560, 'message: <code>smallestMult(20)</code> should return 232792560.');"
], ],
"solutions": [], "solutions": ["function smallestMult(n){\n function gcd(a, b) {\n return b === 0 ? a : gcd(b, a%b); // Euclidean algorithm\n }\n\n function lcm(a, b) {\n return a * b / gcd(a, b);\n }\n var result = 1;\n for(var i = 2; i <= n; i++) {\n result = lcm(result, i);\n }\n return result;\n}"],
"translations": {}, "translations": {},
"challengeSeed": [ "challengeSeed": [
"function euler5() {", "function smallestMult(n) {",
" // Good luck!", " // Good luck!",
" return true;", " return true;",
"}", "}",
"", "",
"euler5();" "smallestMult(20);"
], ],
"description": [ "description": [
"2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.", "2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.",