daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var dates = ["2-2015", "1-2015", "1-2014", "10-2016", "6-2012"];
  2.  
  3. var parseDate = function(date) {
  4.     return date.split("-").map(function(ele) {
  5.         return parseInt(ele);
  6.     });
  7. };
  8.  
  9. dates.sort(function(a, b) {
  10.     a = parseDate(a);
  11.     b = parseDate(b);
  12.    
  13.     var MONTH = 0,
  14.         YEAR = 1;
  15.    
  16.     return a[YEAR] === b[YEAR] ? (
  17.             a[MONTH] < b[MONTH] ? -1 : (a[MONTH] === b[MONTH] ? 0 : 1)
  18.         ) :
  19.         (
  20.             a[YEAR] < b[YEAR] ? -1 : (a[YEAR] === b[YEAR] ? 0 : 1)
  21.         );
  22.    
  23. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top