Jump to content

Viktor9769

New Members
  • Posts

    4
  • Joined

  • Last visited

Community Answers

  1. Viktor9769's post in I have some struggle with a php task.. was marked as the answer   
    $candiesTests = [
        [1, 1, 2, 3], // Test1 => 1,3
        [1, 1, 2, 3, 4], // Test2 => 1,4
        [1, 1, 2, 2, 3, 4, 5, 5], // Test3 => 1,2,5,5
        [1, 1, 2, 2, 3, 4, 5, 5, 1, 1, 5], // Test4 => 1,1,1,2,5
    ];
     
    /**
     * Complete this function
     *
     * @param array $candies A one dimensional array of candies
     *
     * @return array Berit's candies
     */
    function getBeritsCandies(array $candies): array{
        $newarray = array_unique($candies);
        $result= array_diff($newarray,$candies);
        $el = count($candies);
     
        if ($el % 2 == 0) {
            return $newarray;
            # code...
        }
        else {
             return $newarray;
        }
       
     
     
        return [];
     }


     
    /*
     * Code below is just to print answers. Do not edit.
     */
    foreach ($candiesTests as $candies) {
        $beritsCandies = getBeritsCandies($candies);
        echo('Berits candies: '.implode(', ', $beritsCandies).PHP_EOL);
    }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.