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

Commit

Permalink
#30 use for in loop instead of object.keys foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
balintsoos committed Sep 6, 2016
1 parent ff23fe1 commit b78662a
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/proxy/memoryCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,15 @@ module.exports = function(dependencies) {

if (find && typeof find === "object") {
elements = elements.filter(function(item) {
var filter = true;
function convertToRegExp(actItem) {
return (typeof actItem === "string") ? stringToRegExp(actItem) : actItem;
}

function testRegExp(previous, current) {
return previous && current.test(item);
}

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

item = accessProp(item, prop);
Expand All @@ -187,24 +193,19 @@ module.exports = function(dependencies) {

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

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

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

return filter;
}
return true;
});
}

Expand Down

0 comments on commit b78662a

Please sign in to comment.