Guest User

Untitled

a guest
Nov 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. Array.prototype.keySort = function(key, sort){
  2. this.sort(function(a, b) {
  3. if (sort == 'desc') {
  4. var result = (a[key] < b[key]);
  5. } else if (sort == 'asc') {
  6. var result = (a[key] > b[key]);
  7. }
  8. return result ? 1 : -1;
  9. });
  10. return this;
  11. }
  12.  
  13. dataArray.keySort('OrderID', 'asc'); //USAGE
  14. dataArray.keySort('OrderDate', 'desc'); //USAGE
Add Comment
Please, Sign In to add comment