How does Sophia find the median problem?

Hi, everyone
I defined an int array in Sophia. How do I find the middle number in the array
Since Sophia is a functional language, I have been working on this problem for a long time

For example

[10,1,3,8,7,3,5,7,1,9,1]

How do I find an intermediate value in an array?

If possible, please help to write out, thank you

@hanssv.chain @hanssv2 You know what?

  • sort the list (List.sort)
  • if the number of elements is:
    • odd: pick the middle one in the sorted list
    • even: compute the average of the two middle elements (x + y) / 2
2 Likes

Also I think it will help if you don’t think of it as an array :wink:

1 Like