aboutsummaryrefslogtreecommitdiff
path: root/src/utility.js
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-08-26 22:52:02 -0700
committeralon@honor <none@none>2010-08-26 22:52:02 -0700
commitc96ca4ad280e3d9704b8f127311e5b48b707e3bd (patch)
treeb63e654f7df8a9c18f4477edfdec4b26a428424c /src/utility.js
parenta9256705ada4ae335870cdb60ae7f9c8373038e3 (diff)
cleanup + prep for enzymatic2
Diffstat (limited to 'src/utility.js')
-rw-r--r--src/utility.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/utility.js b/src/utility.js
index 447c52a6..f95e81f1 100644
--- a/src/utility.js
+++ b/src/utility.js
@@ -80,3 +80,36 @@ function walkJSON(item, func) {
}
}
+function keys(x) {
+ var ret = [];
+ for (a in x) ret.push(a);
+ return ret;
+}
+
+function values(x) {
+ var ret = [];
+ for (a in x) ret.push(x[a]);
+ return ret;
+}
+
+function sum(x) {
+ return x.reduce(function(a,b) { return a+b }, 0);
+}
+
+function sumTruthy(x) {
+ return x.reduce(function(a,b) { return (!!a)+(!!b) }, 0);
+}
+
+function loopOn(array, func) {
+ for (var i = 0; i < array.length; i++) {
+ func(i, array[i]);
+ }
+}
+
+// Splits out items that pass filter. Returns also the original sans the filtered
+function splitter(array, filter) {
+ var splitOut = array.filter(filter);
+ var leftIn = array.filter(function(x) { return !filter(x) });
+ return { leftIn: leftIn, splitOut: splitOut };
+}
+