A simple Sort By Column function
JesseDahl opened this issue · 1 comments
JesseDahl commented
I've just started using this library recently, so I may just not be using it correctly yet. I was looking for a concise way to sort by a column without having to write a comparator function each time I called it, so I wrote this:
Miso.Dataset.prototype.sortByCol = function(column) {
return this.sort(function(rowA, rowB) {
if (rowA[column] < rowB[column]) {
return -1;
}
if (rowA[column] > rowB[column]) {
return 1;
}
return 0;
});
};
I was wondering if:
- I'm just missing something in the API, and there is already an easy/concise way to sort by column
- If not, is this something that you might want to add to the API?
Also, I'm not sure if this hack works if the column ends up being an object instead of just a basic type. Haven't tested it out yet.
Deleted user commented
Neat extension .. maybe the seed for a Miso plugin project?