Created
September 20, 2012 11:43
-
-
Save ZJONSSON/3755441 to your computer and use it in GitHub Desktop.
d3.f
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
// Function helpers for various array functions | |
d3.f = {} | |
d3.f.get = function (key) { | |
return function(d) { | |
return typeof key === "function" ? key(d) : d[key] | |
} | |
}; | |
["min","max","extent","sum","mean","median","split"] | |
.forEach(function(fn){ | |
d3.f[fn] = function(key) { | |
return function(d) { return d3[fn](d,d3.f.get(key)) } | |
} | |
}); | |
["ascending","descending"] | |
.forEach(function(fn) { | |
d3.f[fn] = function(key) { | |
return function(a,b) { return d3[fn](d3.f.get(key)(a),d3.f.get(key)(b)) } | |
} | |
}) | |
d3.f.first = function(key) { | |
return function(d) { return d3.first(d,d3.f.ascending(key))} | |
} | |
d3.f.last = function(key) { | |
return function(d) { return d3.last(d,d3.f.descending(key))} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment