Well you would need an array of their correct positions obviously. Then make a second array in the function which will be the one you're going to return. Then use a for loop on the first array, and if you find that element in second array add it to the array you're going to return. It would end up in correct order.
PHP Code:
function onCreated() {
this.firstarray = {"One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten"};
this.secondarray = sort({"Three","Nine","Five","Four"});
}
function sort(inarray) {
temp.outarray;
temp.i;
temp.e;
temp.c = inarray.size();
temp.sortarray = this.firstarray;
for (i = 0; i < sortarray.size() && c > 0; i ++) {
e = sortarray[i];
if (inarray.index(e) > -1) {
outarray.add(e);
c--;
}
}
return outarray;
}
That should be the simplest version.