In trying to create a sortable table, I am sorting the underlying array of data:
var g = [
[ 'First Name', 'Last Name', 'Id', 'Age'],
[ 'Joe', 'Blogs', '1', 24],
[ 'Fred', 'Frog', '2', 18],
];
I want to sort everything except the header.
g = g.sort(mycomparison);
is no good, though I could change the comparison routine to always put element[0] in front of everything else.
Instead, I would like to sort everything except the header. The following seems to do what I want, but I wanted to know if there is a better way to express this in javascript. I want to sort the last n-1 elements.
g = g.slice(0,1).concat(g.slice(1,g.length-1).sort(mycomparison))
shift()/unshift(), the code would look more readable IMHOg.sort(function(a,b) { return a === g[0] ? 0 : a[0].localeCompare(b[0]); });