Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 8th, 2020 159 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. function detectAnagrams(string $word, array $possibleAnagrams) : array
  4. {
  5.     $sublist = [];
  6.  
  7.     foreach($possibleAnagrams as $possibleAnagram) {
  8.         if(validate($word, $possibleAnagram)) {
  9.             if(sortString(strtolower($word)) === sortString(strtolower($possibleAnagram))) {
  10.                 $sublist[] = $possibleAnagram;
  11.             }
  12.         }
  13.     }
  14.     return $sublist;
  15. }
  16.  
  17. function sortString(string $string): string
  18. {
  19.     $arr = str_split($string);
  20.     sort($arr);
  21.     return implode($arr);
  22. }
  23.  
  24. function validate($word, $possibleAnagram) {
  25.     return strtolower($word )!== strtolower($possibleAnagram);
  26. }
  27.  
  28. detectAnagrams('corn', ['corn', 'dark', 'Corn', 'rank', 'CORN', 'cron', 'park']);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top