Created
February 27, 2012 21:05
-
-
Save dcousineau/1927114 to your computer and use it in GitHub Desktop.
Care to sort an Object with Underscore anyone? I'm crazy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_.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