// bubble sort / in practice, you rarely write loops in k - here, use < for upsort bs:{n:-1+#x;i:0;do[n;j:0;do[n-i;if[>/x k:j+0 1;x[k]:x@|k];j+:1];i+:1];x}