Skip to content

Commit

Permalink
Update after iteration 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasnorre committed Feb 23, 2024
1 parent d40d80e commit 32c7f62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 12 additions & 12 deletions exercises/practice/food-chain/.meta/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class FoodChain
{
private static array $verse = [
private const VERSE = [
["", ""],
["fly", "I don't know why she swallowed the fly. Perhaps she'll die."],
["spider", "It wriggled and jiggled and tickled inside her."],
Expand All @@ -16,47 +16,47 @@ class FoodChain
["horse", "She's dead, of course!"],
];

public static function verse(int $verseNumber): array
public function verse(int $verseNumber): array
{
$result = [];

$result[] = sprintf("I know an old lady who swallowed a %s.", self::$verse[$verseNumber][0]);
$result[] = self::$verse[$verseNumber][1];
$result[] = sprintf("I know an old lady who swallowed a %s.", self::VERSE[$verseNumber][0]);
$result[] = self::VERSE[$verseNumber][1];
if ($verseNumber === 1 || $verseNumber === 8) {
return $result;
}
for (; $verseNumber > 1; $verseNumber--) {
$text = sprintf(
"She swallowed the %s to catch the %s%s",
self::$verse[$verseNumber][0],
self::$verse[$verseNumber - 1][0],
self::VERSE[$verseNumber][0],
self::VERSE[$verseNumber - 1][0],
$verseNumber !== 3 ? "." : ""
);
if ($verseNumber === 3) {
$text .= " that wriggled and jiggled and tickled inside her.";
}
$result[] = $text;
}
$result[] = self::$verse[$verseNumber][1];
$result[] = self::VERSE[$verseNumber][1];
return $result;
}

public static function verses(int $start, int $end): array
public function verses(int $start, int $end): array
{
if ($start < 1 || $start > $end || $end > 8) {
return self::verse(0);
return $this->verse(0);
}
$s = self::verse($start);
while ($start < $end) {
$start++;
$s[] = "";
$s = array_merge($s, self::verse($start));
$s = array_merge($s, $this->verse($start));
}
return $s;
}

public static function song(): array
public function song(): array
{
return self::verses(1, 8);
return $this->verses(1, 8);
}
}
6 changes: 3 additions & 3 deletions exercises/practice/food-chain/FoodChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@

class FoodChain
{
public static function verse(int $verseNumber): array
public function verse(int $verseNumber): array
{
throw new \BadMethodCallException(sprintf('Implement the %s method', __FUNCTION__));
}

public static function verses(int $start, int $end): array
public function verses(int $start, int $end): array
{
throw new \BadMethodCallException(sprintf('Implement the %s method', __FUNCTION__));
}

public static function song(): array
public function song(): array
{
throw new \BadMethodCallException(sprintf('Implement the %s method', __FUNCTION__));
}
Expand Down

0 comments on commit 32c7f62

Please sign in to comment.