You are viewing a single comment's thread. Return to all comments →
You can make the script easier if you use a native sort method. That way you just shift the array each time.
function cutTheSticks($arr) { sort($arr); $countedValues = array_count_values($arr); while($countedValues) { $results[] = array_sum($countedValues); array_shift($countedValues); } return $results; }
Seems like cookies are disabled on this browser, please enable them to open this website
Cut the sticks
You are viewing a single comment's thread. Return to all comments →
You can make the script easier if you use a native sort method. That way you just shift the array each time.