aboutsummaryrefslogtreecommitdiff
path: root/challenge-276/barroff/julia/ch-2.jl
blob: 59b86550300876f685ffafa52170875e06426b08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env julia

using Test: @test, @testset

function maximum_frequency(ints::Vector{T})::Int where {T<:Integer}
    numbercounts = Dict{T,Int}()
    map(x -> numbercounts[x] = get(numbercounts, x, 0) + 1, ints)
    most_occurrences = maximum(values(numbercounts))
    return count(
        x -> numbercounts[x] == most_occurrences,
        keys(numbercounts)
    ) * most_occurrences
end

@testset "maxumum frequency" begin
    @test maximum_frequency([1, 2, 2, 4, 1, 5]) == 4
    @test maximum_frequency(collect(1:5)) == 5
end