Created
November 11, 2017 17:31
-
-
Save eugenegodun/1e2551f35801d9aaf0a3b1cda5fb70dd to your computer and use it in GitHub Desktop.
JS Bin [https://projecteuler.net/problem=1] // source https://jsbin.com/xoqimiq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="[https://projecteuler.net/problem=1]"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// https://projecteuler.net/problem=1 | |
// The sum of all the multiples of 'a' or 'b' below 'n'. | |
"use strict"; | |
function sumOfMultiplesXYBelowN(x, y, n) { | |
var result = 0; | |
function sum(x, y, n) { | |
var next = n - 1; | |
if (x < y && n <= x || x > y && n <= y) { | |
return result; | |
} | |
if (next % x === 0 || next % y === 0) { | |
result += next; | |
} | |
sum(x, y, next); | |
return result; | |
} | |
return sum(x, y, n); | |
} | |
console.log(sumOfMultiplesXYBelowN(3, 5, 1000)); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript"> | |
// https://projecteuler.net/problem=1 | |
// The sum of all the multiples of 'a' or 'b' below 'n'. | |
function sumOfMultiplesXYBelowN(x, y, n) { | |
let result = 0; | |
function sum(x, y, n) { | |
const next = n - 1; | |
if ((x < y && n <= x) || (x > y && n <= y) ) { | |
return result; | |
} | |
if (next % x === 0 || next % y === 0) { | |
result += next; | |
} | |
sum(x, y, next); | |
return result; | |
} | |
return sum(x, y, n); | |
} | |
console.log(sumOfMultiplesXYBelowN(3, 5, 1000)); | |
</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://projecteuler.net/problem=1 | |
// The sum of all the multiples of 'a' or 'b' below 'n'. | |
"use strict"; | |
function sumOfMultiplesXYBelowN(x, y, n) { | |
var result = 0; | |
function sum(x, y, n) { | |
var next = n - 1; | |
if (x < y && n <= x || x > y && n <= y) { | |
return result; | |
} | |
if (next % x === 0 || next % y === 0) { | |
result += next; | |
} | |
sum(x, y, next); | |
return result; | |
} | |
return sum(x, y, n); | |
} | |
console.log(sumOfMultiplesXYBelowN(3, 5, 1000)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment