KX Community

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

Home Forums KX Academy Fundamentals Capstone 4.3

  • Fundamentals Capstone 4.3

    Posted by emil_barker on February 20, 2024 at 12:00 am

    Hi I have been trying on it but I am not sure what mistake I made on the code

    returnN: {[orderCol;order;N;t] $[order=`top;N# orderCol xasc t;(neg N) # orderCol xasc t]} returnN [`qty;`top;5;edge15]

    Any ideas would be nice thanks!

    chiraggoyal23 replied 3 months, 4 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • megan_mcp

    Administrator
    February 20, 2024 at 12:00 am

    Hi  !

    Have you had a look at the template for returnN ?

    I think a key feature that you could use is sublist – Sublist of a list | Reference | kdb+ and q documentation – Kdb+ and q documentation (kx.com)

    So simply order the table by the column provided in ascending order then subset the first/last N records from the newly ordered table.

    If you are still unsure, please feel free to reach out.

    Many thanks,

    Megan

     

     

     

  • chiraggoyal23

    Member
    March 10, 2024 at 6:35 am

    Looking at the test cases, it seems expected values are wrongly set up.
    While the exercise asks for top 5 values in ascending order, it expects last 5 values in result and vice versa for 2nd test case.
    test.tab:-10?([]col: til 10);

    test.top5col:([]col:5 6 7 8 9);

    test.bottom6:([]col: til 6);

Log in to reply.