Skip to content

Commit

Permalink
[gleam][prime-factors] reverse inside iter function
Browse files Browse the repository at this point in the history
  • Loading branch information
joaofnds committed Nov 11, 2024
1 parent 7a350f7 commit 01c6457
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gleam/prime-factors/src/prime_factors.gleam
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import gleam/list

pub fn factors(value: Int) -> List(Int) {
list.reverse(factors_iter(value, 2, []))
factors_iter(value, 2, [])
}

fn factors_iter(n: Int, i: Int, factors: List(Int)) -> List(Int) {
case n, n % i {
1, _ -> factors
1, _ -> list.reverse(factors)
_, 0 -> factors_iter(n / i, i, [i, ..factors])
_, _ -> factors_iter(n, i + 1, factors)
}
Expand Down

0 comments on commit 01c6457

Please sign in to comment.