function dnfAlgorithm(arr) {
var low = 0;
var mid = 0;
var high = arr.length-1;
var temp;
while(mid <= high) {
console.log(arr);
if(arr[mid] === 0) {
temp = arr[mid];
arr[mid] = arr[low];
arr[low] = temp;
low++;
mid++
}
else if(arr[mid] === 1) {
mid++;
}
else {
temp = arr[mid];
arr[mid] = arr[high];
arr[high] = temp;
high--;
}
}
console.log(arr);
}
dnfAlgorithm([0,2,1,2,1,0,0,1]);