Anonymous user
Averages/Median: Difference between revisions
→{{header|Rust}}: Took out compare function which was masking that there is no way to define an absolute ordering on floats, made it panic instead of silently fail
m (Added Sidef language) |
(→{{header|Rust}}: Took out compare function which was masking that there is no way to define an absolute ordering on floats, made it panic instead of silently fail) |
||
Line 2,186:
Sorting, then obtaining the median element:
<lang rust>
// sort in ascending order, panic on f64::NaN
xs.sort_by(|x,y| x.partial_cmp(y).unwrap() );
if
} else {
xs[n/2]
}
}
fn main() {
let nums = vec![2.,3.,5.,0.,9.,82.,353.,32.,12.];
println!("{:?}", median(nums))
▲ let n = xs.len();
}</lang>
{{out}}
<pre>9</pre>
=={{header|Scala}}==
|