How to sort only the first k elements of an array using sort method?

In reply to Manoj J:

q.sort with (item.index > 5);

This will just separate the elements from 0 to 5 and 6 to $ into 2 groups, but it will not sort.