How do I assert a column/list is ordered in KDB

How do I assert a column/list is ordered in KDB
a: 1 2 3 4;
b: 1 2 3 2;

How can I assert that a is sorted and b is not sorted in KDB?


Clarification I mean this algorithm in Q, as in the linear probe with a short circuit.

def is_sorted(xs):
    i = 1
    while i < len(xs):
        if xs[i] < xs[i - 1]:
            return False
        i += 1
    return True

I assume there's something built in or a simple functional one liner.

Answer

You can just define a function that verifies whether a list is sorted or not

isSorted:{x~asc x}

Enjoyed this article?

Check out more content on our blog or follow us on social media.

Browse more articles