aboutsummaryrefslogtreecommitdiff
path: root/challenge-280/barroff/julia/ch-2.jl
blob: f1115fdc28a9c8080b733d67f082e6bb3e0af04e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/env julia

using Test: @test, @testset

function count_asterisks(str::AbstractString)::Int
    pairless = replace(str, r"\|.*?\|" => "")
    count(x -> x == '*', pairless)
end

@testset "count asterisks" begin
    @test count_asterisks("p|*e*rl|w**e|*ekly|") == 2
    @test count_asterisks("perl") == 0
    @test count_asterisks("th|ewe|e**|k|l***ych|alleng|e") == 5
end