Averages/Median: Difference between revisions
Content deleted Content added
Added J solution. |
→{{header|J}}: Replaced solution with variants by Keith Smilie and Ric Sherlock |
||
Line 316:
The following implementation returns both values for lists with an even number of elements, if those two values are distinct.
<lang j>
median=
</lang>
Another option is to calculate the mean of the two middle values, when two middle values occur.
<lang j>
median=: [: (+/ % #) (<. , >.)@-:@<:@# { /:~
</lang>
|