Skip to content

Commit e30d7d8

Browse files
committed
Coding Challenge for 5-22-22.
1 parent e37fe6e commit e30d7d8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

CC 2022 5-22-22/app.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Return an array containing the numbers from 1 to N, where N is the parametered value.
2+
3+
// Replace certain values however if any of the following conditions are met:
4+
5+
// If the value is a multiple of 3: use the value "Fizz" instead
6+
// If the value is a multiple of 5: use the value "Buzz" instead
7+
// If the value is a multiple of 3 & 5: use the value "FizzBuzz" instead
8+
// N will never be less than 1.
9+
10+
// Method calling example:
11+
12+
// fizzbuzz(3) --> [1, 2, "Fizz"]
13+
14+
function fizzify(i) {
15+
if (i % 15 == 0)
16+
return 'FizzBuzz';
17+
else if (i % 5 == 0)
18+
return 'Buzz';
19+
else if (i % 3 == 0)
20+
return 'Fizz';
21+
else
22+
return i;
23+
}
24+
25+
// Return an array
26+
function fizzbuzz(n) {
27+
var res = [];
28+
for (var i = 1; i <= n; ++i) res.push(fizzify(i));
29+
return res;
30+
}
31+

0 commit comments

Comments
 (0)