Last active
September 4, 2018 06:09
-
-
Save sseidenthal/a9452535ece8642001107f7e0e98e571 to your computer and use it in GitHub Desktop.
Interview Tests, fizzBuzz Example
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 | |
/** | |
* Class Tests | |
* | |
* This are solutions to Interview Tests | |
*/ | |
class Tests { | |
/** | |
* @param $n | |
*/ | |
public function fizzBuzz($n, $fizz_nr = 3, $buzz_nr = 5, $fizz_word = 'Fizz', $buzz_word = 'Buzz') | |
{ | |
for ($i=1; $i<=$n; $i++) { | |
$result = null; | |
if(($i % $fizz_nr) == 0) { | |
$result = $fizz_word; | |
} | |
if(($i % $buzz_nr) == 0) { | |
$result = $buzz_word; | |
} | |
if(($i % ($fizz_nr * $buzz_nr)) == 0) { | |
$result = $fizz_word . $buzz_word; | |
} | |
if(is_null($result)) { | |
$result = $i; | |
} | |
echo $result . "\n"; | |
} | |
} | |
} | |
$tests = new Tests(); | |
$tests->fizzBuzz(100, 3, 5); |
Author
sseidenthal
commented
Sep 4, 2018
•
- created a little more elegant and flexible solution
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment