Skip to content

Instantly share code, notes, and snippets.

@CrossEye
Forked from buzzdecafe/where.js
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CrossEye/8980419 to your computer and use it in GitHub Desktop.
Save CrossEye/8980419 to your computer and use it in GitHub Desktop.
var where = curry(function where(matchThis, testObj) {
return ramda.all(function (key) {
var val = matchThis[key];
return typeof val == "function" ? val(testObj[key], testObj) :
(testObj[key] === matchThis[key]);
}, Object.keys(matchThis));
});
x1y2 = where({x: 1, y: 2});
x1y2({x: 1}); //=> false
x1y2({x: 1, y: 2}); //=> true
x1y2({x: 1, y: 2, z: 3}); //=> true
xlt1 = where({x: function(val) {return val < 1;}});
xlt1({x: 1}); //=> false
xlt1({x: 0}); //=> true
triangle = where({
a: function(a, obj) {return a < obj.b + obj.c;},
b: function(b, obj) {return b < obj.a + obj.c;},
c: function(c, obj) {return c < obj.a + obj.b;}
});
triangle({a: 3, b: 4, c: 5}); //=> true;
triangle({a: 6, b: 8, c: 9}); //=> true;
triangle({a: 2, b: 8, c: 12}); //=> false;
triangle({a: 3, b: 11, c: 5}); //=> false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment