Skip to content

Instantly share code, notes, and snippets.

@sseidenthal
Last active September 4, 2018 06:09
Show Gist options
  • Save sseidenthal/a9452535ece8642001107f7e0e98e571 to your computer and use it in GitHub Desktop.
Save sseidenthal/a9452535ece8642001107f7e0e98e571 to your computer and use it in GitHub Desktop.
Interview Tests, fizzBuzz Example
<?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);
@sseidenthal
Copy link
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