KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums KX Academy Exercise 16: – Use indexing to find the middle value in the `sortedFares` list.

  • Exercise 16: – Use indexing to find the middle value in the `sortedFares` list.

    Posted by natasha-lakhpaty on March 8, 2024 at 8:02 am

    Hi

    I used med sorted fares for this exercise and my output was 43.8.

    The solution utilises sortedFares [`long$(count sortedFares)%2] with an output of 43.9.

    The solution formula also appears to look like a median calculation. Can anyone advise why they differ and why the solution answer is the accurate one pls? Thanks

    natasha-lakhpaty replied 8 months, 2 weeks ago 2 Members · 2 Replies
  • 2 Replies
  • mwoods

    Administrator
    March 8, 2024 at 11:35 am

    Hi @natasha-lakhpaty the indexing approach taken in the exercise solution returns the value at the index that is halfway between the sorted list.

    The med function doesn’t have to return an actual distinct value that exists in the list, but instead the arithmetic middle value. Have added a simpler example here – hope this helps!

  • natasha-lakhpaty

    Member
    March 11, 2024 at 1:14 am

    hi I understand now. In the case of middle values that are 2 values (ie where in the case of the median an average would be found) which middle value will the query result in- the first or the second?

Log in to reply.