Recently I got a different version of the "fizzbuzz question" that ask you to do this:
implement function fizzBuzz(n, conditions)
where n is an integer and condition is a map of key: value (number: string)
you need to run on all the numbers from 1 to n, and for each number, you need to check which conditions it fulfills if non then print the number, but if a condition X is fulfilled and you can get X from Y * Z then print the only X and not Y * Z
exmaples:
input: n = 100
condition = {
3: 'fizz:',
5: 'buzz',
15: 'foo'
}
will print: 1,2,fizz,4,buzz,fizz,7,8,fizz,10,11,fizz,13,14,**foo**
which mean for 15 it will print only foo. but if the condition object was:
condition = {
3: 'fizz:',
5: 'buzz',
}
then the output would be the same but on 15 it would print 'fizzbuzz' (both 3+5)
example:
condition = {
2: 'boo',
3: 'fizz:',
5: 'buzz',
}
for 30 it will print boofizzbuzz (2+3+5)
How would you solve this?