blob: 153153ee65657dee3368276a232798690a7ee90f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import gleam/string
pub fn count_leading_hashes(line: String) -> Int {
do_count_leading_hashes(string.to_graphemes(line), 0)
}
fn do_count_leading_hashes(characters: List(String), accumulator: Int) -> Int {
case characters {
[c, ..rest] -> {
case c {
"#" -> do_count_leading_hashes(rest, accumulator + 1)
_ -> accumulator
}
}
_ -> accumulator
}
}
|