2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								id: 5a23c84252665b21eecc7e78
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								title: General FizzBuzz
							 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								challengeType: 5
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								forumTopicId: 302273
							 
						 
					
						
							
								
									
										
										
										
											2021-01-13 03:31:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								dashedName: general-fizzbuzz
							 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-12-16 00:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --description--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Write a generalized version of [FizzBuzz ](https://rosettacode.org/wiki/FizzBuzz ) that works for any list of factors, along with their words.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This is basically a "fizzbuzz" implementation where the rules of the game are supplied to the user. Create a function to implement this. The function should take two parameters.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The first will be an array with the FizzBuzz rules. For example: `[ [3, "Fizz"] , [5, "Buzz"] ]` .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This indicates that `Fizz`  should be printed if the number is a multiple of 3 and `Buzz`  if it is a multiple of 5. If it is a multiple of both then the strings should be concatenated in the order specified in the array. In this case, `FizzBuzz`  if the number is a multiple of 3 and 5.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The second parameter is the number for which the function should return a string as stated above.
							 
						 
					
						
							
								
									
										
										
										
											2020-12-16 00:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --hints--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`genFizzBuzz`  should be a function. 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-12-16 00:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(typeof genFizzBuzz == 'function');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 6)`  should return a string. 
						 
					
						
							
								
									
										
										
										
											2020-12-16 00:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  typeof genFizzBuzz(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [3, 'Fizz'],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [5, 'Buzz']
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    6
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ) == 'string'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 6)`  should return `"Fizz"` . 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-12-16 00:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert.equal(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  genFizzBuzz(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [3, 'Fizz'],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [5, 'Buzz']
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    6
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  'Fizz'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 10)`  should return `"Buzz"` . 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2020-12-16 00:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								assert.equal(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  genFizzBuzz(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [3, 'Fizz'],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [5, 'Buzz']
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    10
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  'Buzz'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 12)`  should return `"Buzz"` . 
						 
					
						
							
								
									
										
										
										
											2020-12-16 00:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert.equal(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  genFizzBuzz(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [3, 'Buzz'],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [5, 'Fizz']
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    12
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  'Buzz'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 13)`  should return `"13"` . 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-12-16 00:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert.equal(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  genFizzBuzz(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [3, 'Buzz'],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [5, 'Fizz']
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    13
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  '13'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 15)`  should return `"BuzzFizz"` . 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2020-12-16 00:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								assert.equal(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  genFizzBuzz(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [3, 'Buzz'],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [5, 'Fizz']
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    15
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  'BuzzFizz'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 15)`  should return `"FizzBuzz"` . 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-12-16 00:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert.equal(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  genFizzBuzz(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [3, 'Fizz'],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [5, 'Buzz']
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    15
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  'FizzBuzz'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-06 04:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`genFizzBuzz([[3, "Fizz"],[5, "Buzz"],[7, "Baxx"]], 105)`  should return `"FizzBuzzBaxx"` . 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2020-12-16 00:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								assert.equal(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  genFizzBuzz(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [3, 'Fizz'],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [5, 'Buzz'],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      [7, 'Baxx']
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    105
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  'FizzBuzzBaxx'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
									
										
										
										
											2018-10-10 18:03:03 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2020-08-13 17:24:35 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-13 03:31:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --seed--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## --seed-contents--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function genFizzBuzz(rules, num) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-12-16 00:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --solutions--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-13 03:31:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function genFizzBuzz(rules, num) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  let res='';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  rules.forEach(function (e) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if(num % e[0] == 0)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      res+=e[1];
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if(res==''){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    res=num.toString();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return res;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```