Created
September 9, 2011 17:51
-
-
Save richardcpeterson/1206868 to your computer and use it in GitHub Desktop.
JavaScript function to select from array of objects
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 select (a) { | |
return { | |
from : function (b) { | |
return { | |
where : function (c) { | |
return { | |
equals : function (d) { | |
var foo = []; | |
for (prop in b){ | |
if (b[prop][c] == d){ | |
foo.push(b[prop][a]); | |
} | |
} | |
return foo; | |
}, | |
contains : function (d) { | |
var foo = []; | |
for (prop in b){ | |
if (b[prop][c].indexOf(d) != -1){ | |
foo.push(b[prop][a]); | |
} | |
} | |
return foo; | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment