Sha256: 92df8e0b4348b43f1d7a72b1cfa1dbcc73c87741ed730e753ee7086eb3797be0
Contents?: true
Size: 767 Bytes
Versions: 396
Compression:
Stored size: 767 Bytes
Contents
<?php function detectAnagrams($anagram, array $possibleMatches) { $matches = []; foreach ($possibleMatches as $possibleMatch) { $anagramLetters = str_split(mb_strtolower($anagram)); $matchLetters = str_split(mb_strtolower($possibleMatch)); if (count($anagramLetters) === count($matchLetters) and $anagramLetters !== $matchLetters) { foreach ($matchLetters as $character) { $index = array_search($character, $anagramLetters); if ($index !== false) { unset($anagramLetters[$index]); } if (empty($anagramLetters)) { $matches[] = $possibleMatch; } } } } return $matches; }
Version data entries
396 entries across 396 versions & 1 rubygems