Jump to content

General FizzBuzz: Difference between revisions

→‎Names solution: Added syntactic sugar.
(OCaml implementation)
(→‎Names solution: Added syntactic sugar.)
Line 2,881:
 
===Names solution===
If we deviate from the task's example of how to input parameters and instead use R's names functionfacilities to make our (number, name) pairs, we get a much cleaner solution.
<lang r>namedGenFizzBuzz<-function(n,namedNums)
{
Line 2,892:
invisible()
}
namedNums<-c(Fizz=3,Buzz=5,Baxx=7)#Notice that we can name our inputs without a call to names
namedNums<-c(3,5,7); names(namedNums)<-c("Fizz","Buzz","Baxx")
namedGenFizzBuzz(105,namedNums)
shuffledNamedNums<-c(Buzz=5,Prax=9,Fizz=3,Baxx=7); names(shuffledNamedNums)<-c("Buzz","Prax","Fizz","Baxx")
namedGenFizzBuzz(105,shuffledNamedNums)</lang>
 
331

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.