Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active September 21, 2020 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/6120fffdc8e20d39bfe3157a63f5d0fd to your computer and use it in GitHub Desktop.
Save lbvf50mobile/6120fffdc8e20d39bfe3157a63f5d0fd to your computer and use it in GitHub Desktop.
Just PHP FUN 108.
<?php
# https://www.codewars.com/kata/585d8c8a28bc7403ea0000c3 Find the unique string.
function find_uniq($a) {
$hash = [];
foreach($a as $v){
$h = str_split(preg_replace('/\s/','',strtolower($v)));
sort($h);
$h = implode(array_unique($h));
if(!isset($hash[$h])){
$hash[$h] = [];
}
array_push($hash[$h],$v);
}
foreach($hash as $v) if(1 == count($v)) return $v[0];
throw new Exception('No answer.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment