View Single Post
  #3  
Old 11-03-2010, 05:36 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
It would be really cool if we had a built-in sort function that let us specify our own function for comparing objects (similar to c or java sorting methods).

example:
PHP Code:
temp.arr = {3412214421337};
temp.func = function(ab) { // should return <0 if (a < b), >0 if (a > b), or ==0 if (a == b)
  // do whatever you want to compare a and b
  // ex:
  
return b;
};

temp.arr.sort(..., temp.func); // would sort the array using my compare function 
I'm not sure if the above is syntactically correct...probably not, but you get the idea.

Actually, I might try to do something like this later when I'm not busy, but built-in would be better!

edit: bubble sort is a terrible sorting algorithm, and if you don't need to specify a specific order, you should stick to built-in sorting which probably uses quicksort or some other O(nlogn) sorting algorithm.
__________________
Reply With Quote