Skip to content

Instantly share code, notes, and snippets.

@dcousineau
Created February 27, 2012 21:05
Show Gist options
  • Save dcousineau/1927114 to your computer and use it in GitHub Desktop.
Save dcousineau/1927114 to your computer and use it in GitHub Desktop.
Care to sort an Object with Underscore anyone? I'm crazy
_.extend(request.params, {
AWSAccessKeyId: this.key
, SignatureVersion: 2
, SignatureMethod: 'HmacSHA256'
, Version: request.opts.version || '2009-04-15'
, Timestamp: new Date().toISOString()
});
var sortedParams = _(request.params).chain()
.map(function(v, k) { return [k,v]; })
.sortBy(function(a) { return a[0]; })
.reduce(function(s, v){ s[v[0]] = v[1]; return s; }, {})
.value();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment