This is the task.
* Adam has been given a bag of candies from his mother.
* His mother told him to share half of it with his sister Berit.
* Adam likes diversity so he wants as many different types of candies as possible, while giving the rest to Berit.
* If Adam has received an odd number of candies he can keep one more than he gives to Berit.
*
* The exercise is to sort through the candies Adam has been given and return the candies that he should give to Berit.
*/
/*
* Several different test cases, add one below if you like.
* Each value correspond to a different type of candy.
*
* The values after => is the values that should be returned for each test case.
*/
/*$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
*
* u/param array $candies A one dimensional array of candies
*
* u/return array Berit's candies
*/
function getBeritsCandies(array $candies): array{
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);
}
I am so stuck.. When im using the array_unique function the duplicates dissapear, I want an "reverse" array_unique maybe? can someone help a lost soul out?