Object Search Algorithm Challenge
functionwhere (collection, source) {vararr = [];varStatus =NULL;//What's in a name? for(vari = 0; i < collection.length; i++) { for(varImpinchsource) { if(Source[imp]!==Collection[i][imp]) {Status= 0; Break; } Status= 1; } if(Status = = 1) {Arr.push (collection[i]); }}returnarr;} where ([{first:"Romeo", Last: "Montague"}, {first: ' Mercutio ', Last:NULL}, {first: ' Tybalt ', Last: ' Capulet '}], {last: "Capulet"});
Wouldn't it be better to write like this than use the following?
functionwhere (collection, source) {vararr = [], index = 0;//What's in a name?//Console.log (object.getownpropertynames (source). length);//get the number of object properties for(; index < collection.length; index++) { for(varKeyinchCollection[index]) { varCount = 0; for(varKey2inchsource) { if(Collection[index].hasownproperty (Key2)) {if(Source[key2] = =Collection[index][key2]) {Count++; } if(Count = = object.getownpropertynames (source). length && key = =Key2) {Arr.push (Collection[index]); } } } } } returnarr;}
Javascript-Object Search Algorithm Challenge