Created
January 30, 2021 21:22
-
-
Save stevebauman/bffe5c8296a6c09dc63e0aecf1554e2f to your computer and use it in GitHub Desktop.
Thesaurus Challenge
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 Thesaurus | |
{ | |
private $thesaurus; | |
function __construct(array $thesaurus) | |
{ | |
$this->thesaurus = $thesaurus; | |
} | |
public function getSynonyms(string $word) : string | |
{ | |
return json_encode([ | |
'word' => $word, | |
'synonyms' => $this->thesaurus[$word] ?? [] | |
]); | |
} | |
} | |
$thesaurus = new Thesaurus( | |
[ | |
"buy" => array("purchase"), | |
"big" => array("great", "large") | |
] | |
); | |
//{"word":"big","synonyms":["great","large"]} | |
echo $thesaurus->getSynonyms("big"); | |
echo "\n"; | |
//{"word":"agelast","synonyms":[]} | |
echo $thesaurus->getSynonyms("agelast"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment