Skip to content

Commit

Permalink
fix median algorithm of math package
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Aug 19, 2023
1 parent 2b218a2 commit 2ab63be
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions math/median.jule
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use sort::{
quick_sort,
}
use sort::{quick_sort}

pub fn median(mut slice: []int): f64 {
slice = quick_sort(slice)
let length: int = slice.len
let mut median: f64 = 0

if length % 2 == 0 {
median = (slice[(length / 2) - 1] + slice[(length / 2)]) / 2.0
} else {
median = slice[length/2]
}
let l = slice.len
match {
| l == 0:
ret 0

| l%2 == 0:
ret f64(slice[l/2-1] + slice[l/2]) / 2

ret median
|:
ret f64(slice[l/2])
}
}

0 comments on commit 2ab63be

Please sign in to comment.