I\'ve made a solution for the Dutch national flag problem already.
But this time, I want to try something more difficult: the Mauritus national flag problem - 4 colours,
I do have a similar kind of code but insted of
function sort(a:string[]){
let low = 0;
let mid1 = 0;
let mid2 = a.length-1;
let high = a.length-1;
while(mid1 <= mid2){
switch(a[mid1]){
case '0':
[a[mid1],a[low]] = [a[low],a[mid1]];
mid1++;
low++;
break;
case '1':mid1++;break;
case '2':
case '3':[a[mid1],a[mid2]] = [a[mid2],a[mid1]];
mid2--;
break;
}
}
//sort 2 and 3
while(mid1 <= high){
switch(a[mid1]){
case '2': mid1++; break;
case '3': [a[mid1],a[high]] = [a[high],a[mid1]]
high--;
break;
}
}
}