If you are sorting large arrays, its better to do a date conversion just once,
rather than repeating the creation on every jiggle of the sort routine.
function unaturalSort(arr){
var T= arr.slice(0), L= T.length, i, itm, next;
// create a timestamp for each element
for(i= 0; i<L; i++){
itm= T[i];
next= T[i][0];
T[i]= [+new Date(next), itm];
}
T.sort(function(a, b){
return a[0]-b[0]
});
//remove the timestamps from the sorted array
for(i= 0; i<L; i++){
T[i]= T[i][1];
}
return T;
}
var A= [
["2013/09/09", 1, 2], ["2013/12/31", 2, 5],
["2014/12/30", 1, 4],["2013/04/17", 1, 1]
];
unaturalSort(A).join('\n');
returned value: (String)
2013/04/17, 1, 1
2013/09/09, 1, 2
2013/12/31, 2, 5
2014/12/30, 1, 4
Note- skip the slice(), if you mean to rearrange the existing array.