DEV Community

loading...

Discussion on: These problem-solving patterns will help you ace your next coding interview

jonrandy profile image
Jon Randy

And in PHP (again, no join needed):

function isAnagram($str1, $str2) {
   $s1 = str_split($str1);
   $s2 = str_split($str2);
   sort($s1);
   sort($s2);
   return $s1 == $s2;
}
Enter fullscreen mode Exit fullscreen mode
Thread Thread
jonrandy profile image
Jon Randy

And in Ruby:

def is_anagram(str1, str2)
  str1.split('').sort() == str2.split('').sort()
end
Enter fullscreen mode Exit fullscreen mode