Another one of the scalability aspects that we can explore is that what if the game wont stop at just 2 denominators (e.g. If I add 7 to the game, so for numbers multiple of 3 print Fizz, multiple of 5 print Buzz, multiple of 15 (3 and 5) print FizzBuzz, multiple of 35 (5 and 7) print BuzzBazz, multiple of 21 (3 and 7) print FizzBazz, and multiple of 105 (3 and 5 and 7) print FizzBuzzBazz). How we would go about scale it up on this aspect is to make use of hashmap, iterating through the map to determine the output. Here is the implementation in Go:
packagemainimport("fmt""sort""strconv")funcscalableFizzBuzz(numint,denominatorsMapmap[int]string){// make a list of keys and sort it in order from small -> large// this is to make sure that it prints out "FizzBuzzBazz"// instead of random order like "BuzzFizzBazz" due to the// random nature of map iteratorkeys:=make([]int,0)fork:=rangedenominatorsMap{keys=append(keys,k)}sort.Ints(keys)fori:=1;i<=num;i++{output:=""for_,k:=rangekeys{ifi%k==0{output+=denominatorsMap[k]}}ifoutput==""{output+=strconv.Itoa(i)}output+=", "fmt.Print(output)}}funcmain(){scalableFizzBuzz(300,map[int]string{3:"Fizz",5:"Buzz",7:"Bazz"})}
He/Him/His
I'm a Software Engineer and a teacher.
There's no feeling quite like the one you get when you watch someone's eyes light up learning something they didn't know.
Another one of the scalability aspects that we can explore is that what if the game wont stop at just 2 denominators (e.g. If I add 7 to the game, so for numbers multiple of 3 print Fizz, multiple of 5 print Buzz, multiple of 15 (3 and 5) print FizzBuzz, multiple of 35 (5 and 7) print BuzzBazz, multiple of 21 (3 and 7) print FizzBazz, and multiple of 105 (3 and 5 and 7) print FizzBuzzBazz). How we would go about scale it up on this aspect is to make use of hashmap, iterating through the map to determine the output. Here is the implementation in Go:
Here is the solution in js
Nice, I never thought of scaling it in that direction.
I like the idea of using a Hash.