Skip to content

Instantly share code, notes, and snippets.

@stevebauman
Created January 30, 2021 21:22
Show Gist options
  • Save stevebauman/bffe5c8296a6c09dc63e0aecf1554e2f to your computer and use it in GitHub Desktop.
Save stevebauman/bffe5c8296a6c09dc63e0aecf1554e2f to your computer and use it in GitHub Desktop.
Thesaurus Challenge
<?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