Created
September 18, 2010 08:54
-
-
Save DaRaFF/585508 to your computer and use it in GitHub Desktop.
Vergleich Java / PHP / Javascript - Teil 2
This file contains hidden or 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
| package fizzbuzz; | |
| public class FizzBuzzSequence { | |
| private FizzBuzz _fizzBuzz; | |
| public FizzBuzzSequence() { | |
| _fizzBuzz = new FizzBuzz(); | |
| } | |
| public String getFizzBuzzSequence(int start, int stop) { | |
| String calculatedString = ""; | |
| String arr[] = new String[stop - start + 1]; | |
| for (int i = start; i <= stop; i++) { | |
| arr[i-1] = _fizzBuzz.getFizzBuzzValueOf(i); | |
| } | |
| calculatedString = FizzBuzzSequence.implode(arr, ","); | |
| return calculatedString; | |
| } | |
| /** | |
| * Helperfunktion - Wandelt die Inhalte eines Arrays in eine String um | |
| * @param ary Array, welcher umgewandelt werden soll | |
| * @param delim Trennzeichen zwischen den einzelnen Elementen | |
| * @return Umgewandelter String | |
| */ | |
| public static String implode(String[] ary, String delim) { | |
| String out = ""; | |
| for (int i = 0; i < ary.length; i++) { | |
| if (i != 0) { | |
| out += delim; | |
| } | |
| out += ary[i]; | |
| } | |
| return out; | |
| } | |
| } |
This file contains hidden or 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
| var FizzBuzzSequence = function(start, end){ | |
| var start = start; | |
| var end = end; | |
| var calculatedString = ''; | |
| (function(){ | |
| var arr = []; | |
| for (i = start; i <= end; i++) { | |
| var value = FizzBuzz.getFizzBuzzValueOf(i); | |
| arr.push(value); | |
| calculatedString = arr.join(','); | |
| } | |
| }()); | |
| this.getString = function(){ | |
| return calculatedString; | |
| } | |
| } |
This file contains hidden or 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 | |
| require_once 'FizzBuzz.php'; | |
| class FizzBuzzSequence { | |
| private $_fizzBuzz; | |
| function __construct() { | |
| $this->_fizzBuzz = new FizzBuzz(); | |
| } | |
| public function getFizzBuzzSequence($start, $stop) { | |
| $calculatedString = ""; | |
| for ($i = $start; $i <= $stop; $i++) { | |
| $arr[] = $this->_fizzBuzz->getFizzBuzzValueOf($i); | |
| } | |
| $calculatedString = implode(",", $arr); | |
| return $calculatedString; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment