Last active
August 29, 2015 14:07
-
-
Save codenamegary/fbee6e68a4e252501b54 to your computer and use it in GitHub Desktop.
Functional FizzBuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$zork = function($result, $mod) { | |
return function($num)use($result, $mod) { | |
return $num % $mod ? '' : $result; | |
}; | |
}; | |
$fizz = $zork('Fizz', 3); | |
$buzz = $zork('Buzz', 5); | |
$spluge = function($fizz, $buzz) { | |
return function($num)use($fizz, $buzz) { | |
return $fizz($num) . $buzz($num) ?: $num; | |
}; | |
}; | |
$fizzBuzz = $spluge($fizz, $buzz); | |
$i = 0; | |
while($i<100) { | |
echo $fizzBuzz($i) . "\n"; | |
$i++; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment