Skip to content

Instantly share code, notes, and snippets.

@marcel-jahn
Created August 3, 2017 12:25
Show Gist options
  • Save marcel-jahn/65193ebce407f56cba1c6041074c8107 to your computer and use it in GitHub Desktop.
Save marcel-jahn/65193ebce407f56cba1c6041074c8107 to your computer and use it in GitHub Desktop.
Sorting by ascending date with Underscore.js
var list = [
{id: 1, created_at: 'Sun Feb 22 23:19:08 +0000 2009'},
{id: 2, created_at: 'Wed Jun 05 14:07:04 +0000 2013'},
{id: 3, created_at: 'Wed Jun 05 10:11:30 +0000 2013'},
{id: 3, created_at: 'Wed Jun 05 14:01:08 +0000 2013'}
];
var sorted = _.sortBy(list,function(node){
return - (new Date(node.created_at).getTime());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment