HH\Lib\Dict\count_values

Meta Engineer?

This is available as Dict\count_values in the www repository.

Returns a new dict mapping each value to the number of times it appears in the given Traversable

namespace HH\Lib\Dict;

function count_values<Tv as arraykey>(
  Traversable<Tv> $values,
): dict<Tv, int>;

Time complexity: O(n) Space complexity: O(n)

Parameters

Returns

  • dict<Tv, int>

Examples

$result = Dict\count_values(vec[1,2,2,3,3,3]);
print_r($result);
//result: dict[1=>1, 2=>2, 3=>3]

$result = Dict\count_values(vec[0,0,0,0,0]);
print_r($result);
//result: dict[0=>5]