Skip to content

Instantly share code, notes, and snippets.

@codenamegary
Last active August 29, 2015 14:07
Show Gist options
  • Save codenamegary/fbee6e68a4e252501b54 to your computer and use it in GitHub Desktop.
Save codenamegary/fbee6e68a4e252501b54 to your computer and use it in GitHub Desktop.
Functional FizzBuzz
<?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