RosettaCodeData/Task/General-FizzBuzz/Sidef/general-fizzbuzz.sidef
2023-07-01 13:44:08 -04:00

19 lines
502 B
Text
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class FizzBuzz(schema=Hash(<3 Fizz 5 Buzz>...)) {
method filter(this) {
var fb = ''
schema.sort_by {|k,_| k.to_i }.each { |pair|
fb += (pair[0].to_i `divides` this ? pair[1] : '')
}
fb.len > 0 ? fb : this
}
}
 
func GeneralFizzBuzz(upto, schema) {
var ping = FizzBuzz()
if (nil != schema) {
ping.schema = schema.to_hash
}
(1..upto).map {|i| ping.filter(i) }
}
 
GeneralFizzBuzz(20, <3 Fizz 5 Buzz 7 Baxx>).each { .say }