Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
#30 find in array fix
Browse files Browse the repository at this point in the history
  • Loading branch information
balintsoos committed Sep 6, 2016
1 parent ed691df commit ba768e2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/proxy/memoryCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ module.exports = function(dependencies) {

if (find && typeof find === "object") {
elements = elements.filter(function(item) {
var filter = true;

Object.keys(find).forEach(function(prop) {
var act = find[prop];

Expand All @@ -185,21 +187,24 @@ module.exports = function(dependencies) {

if (act instanceof RegExp) {
if (!act.test(item)) {
return false;
filter = false;
}
} else if (Array.isArray(act)) {
act.map(function(actItem) {
var regExpArray = act.map(function(actItem) {
return (typeof actItem === "string") ? stringToRegExp(actItem) : actItem;
});

return act.reduce(function(previous, current) {
var result = regExpArray.reduce(function(previous, current) {
return previous && current.test(item);
}, true);

filter = result;
} else if (act !== item) {
return false;
filter = false;
}
});
return true;

return filter;
});
}

Expand Down

0 comments on commit ba768e2

Please sign in to comment.