-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfizzBuzz.js
33 lines (29 loc) · 852 Bytes
/
fizzBuzz.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function solution1(input) {
for(let i = 1; i <= input; i++) {
if(i % 3 === 0 && i % 5 === 0) console.log("fizzBuzz");
else if(i % 3 === 0) console.log("fizz");
else if(i % 5 === 0) console.log("buzz");
else console.log(i);
}
return "Solution printed";
}
function solution2(input) {
for(let i = 1; i <= input; i++) {
let message = "";
if(i % 3 === 0) message += "fizz";
if(i % 5 === 0) message += "buzz";
console.log(message || i);
}
return "Solution printed";
}
function run() {
const inputs = [5, 15, 20, 17];
const solutionsCount = 2;
for (let s = 0; s < solutionsCount; s++) {
for (let i = 0; i < inputs.length; i++) {
const answer = eval(`solution${s + 1}('${inputs[i]}')`);
console.log(`solution${s + 1} : ${inputs[i]} => ${answer}`);
}
}
}
run();