Advertisement
Anatoliy_Gerasimov

Test task

Aug 30th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.46 KB | None | 0 0
  1. function checkArray(Array $originArray): bool
  2. {
  3.     //convert array to lowercase with save type
  4.     $array = array_map(function($item) {
  5.         return is_string($item) ? strtolower($item) : $item;
  6.     }, $originArray);
  7.  
  8.     //calculate duplicates and return result
  9.     foreach ($array as $item) {
  10.         $duplicates = array_keys($array, $item, true);
  11.         if (count($duplicates) % 2 == 0) {
  12.             return true;
  13.         }
  14.     }
  15.  
  16.     return false;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement