File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ var obj = {
2+ 'homes' : [ {
3+ "home_id" : "1" ,
4+ "price" : "925" ,
5+ "sqft" : "1100" ,
6+ "num_of_beds" : "2" ,
7+ "num_of_baths" : "2.0" ,
8+ } , {
9+ "home_id" : "2" ,
10+ "price" : "1425" ,
11+ "sqft" : "1900" ,
12+ "num_of_beds" : "4" ,
13+ "num_of_baths" : "2.5" ,
14+ } ,
15+ // ... (more homes) ...
16+ ]
17+ } ;
18+ // (Note that because `price` and such are given as strings in your object,
19+ // the below relies on the fact that <= and >= with a string and number
20+ // will coerce the string to a number before comparing.)
21+ var newArray = obj . homes . filter ( function ( el ) {
22+ return el . price <= 1000 &&
23+ el . sqft >= 500 &&
24+ el . num_of_beds >= 2 &&
25+ el . num_of_baths >= 1.5 ; // Changed this so a home would match
26+ } ) ;
27+ console . log ( newArray ) ;
You can’t perform that action at this time.
0 commit comments