javascript - How to rewrite loop to recursion -


i implemented search function , loop search collection. in first iteration need search collection, next iterations result of first iteration. use if-statement if (i >= 1) collection = result; it, it's not safe because need save collection. possible rewrite loop recursion function? how can make or make code elegant?

var targets = target.split(' '); // => ['hello', 'world'];  (var = 0; < targets.length; ++i) {     if (i >= 1) {         collection = result;     }     result = includes(collection, props, targets[i]); } 

my search function:

function includes(collection, props, target) {     var result = [];     var collection_length = collection.length;     var props_length = props.length;     var target_length = target.length;      (var = 0; < collection_length; ++i) {         (var j = 0; j < props_length; ++j) {             if (collection[i][props[j]]) {                 if (collection[i][props[j]].tolowercase().slice(0, target_length) === target) {                     result.push(collection[i]);                     continue;                 }             }         }     }      return result.length !== 0 ? result : false; }  

var result = collection; (var = 0; < targets.length; ++i) {     result = includes(result, props, targets[i]); } 

maybe i'm missing isn't you're trying do?


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -