From b78662a0c243986770786e5927064ffd91833d29 Mon Sep 17 00:00:00 2001 From: Balint Soos Date: Tue, 6 Sep 2016 15:48:48 +0200 Subject: [PATCH] #30 use for in loop instead of object.keys foreach --- src/proxy/memoryCore.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/proxy/memoryCore.js b/src/proxy/memoryCore.js index 6e9b956..a83b7dc 100644 --- a/src/proxy/memoryCore.js +++ b/src/proxy/memoryCore.js @@ -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); @@ -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; }); }