I'm trying to call a function recursively (for sorting purposes) but getting an error. I tried to find a solution and found How to call function recursively; I changed my code accordingly, so now it looks like this:
$scope.orderCustom = function() {
qS.quickSort($scope.mydata, 0, mydata.length-1);
};
var qS = {
quickSort: function quickSort(data, min, max) {
if (min < max) {
var p = qSP.quickSortPartition(data, min, max);
var newMax = p-1;
var newMin = p+1;
qS.quicksort(data, min, newMax);
qS.quicksort(data, newMin, max);
}
}
};
var qSP = {
quickSortPartition: function quickSortPartition(data, min, max) {
var pivot = data[max].id;
var i = min;
for (var j = min; j <= max; j++) {
if (data[j].id <= pivot) {
var pom = data[j];
data[j] = data[i];
data[i] = pom;
i = i+1;
}
}
var pom = data[i];
data[i] = data[max];
data[max] = pom;
return i;
}
};
I'm getting an error "Error: qS.quicksort is not a function". Does anyone know how to solve this problem? I am still not able to leave a comment on stackoverflow, so I had to open a new question for this. Any help would be appriciated. Thanx :)
quickSort