File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments