Ad
  • Default User Avatar

    It is a question not an issue. The tests are the same in all languages and 6749 guys passed the kata.

  • Custom User Avatar

    In my solution, I test these conditions at the top but it still does not pass the test cases when length of a and b are 0. It should return false but my code is returning true.

    if((a==null) || (b==null))
    {
      return false;
    }
    else if(a.length==0 || b.length==0)
    {
      return false;
    }
    else if(a.length != b.length)
    {
      return false;
    }
    

    I tried everything but can not resolve the issue. I post the whole code if you want.

  • Custom User Avatar

    So, been struggling with this for an hour now, and i can't quite understand what i'm doing wrong. i even quit the kata to see the answers, but i still want to know what was wrong with my solution. any reply will be highly appreciated.
    my code below (nowhere near good practice probably but i'm new to php so i'm trying to understand the concept before using methods like array_map()

    function comp($a1, $a2) {
    $answer = true;
    $arr = array();
    foreach($a1 as $val) {
    $sqr = $val*$val;
    array_push($arr, $sqr);
    }
    sort($arr);
    sort($a2);
    if (is_null($a1) || is_null($a2) || $arr != $a2 || count($arr) != count($a2) || !is_array($a1) || !is_array($a2) || count($a1) == 0 || count($a2) == 0){
    return false;
    } else {
    return true;
    }
    }