Skip to content

Commit 296538b

Browse files
Merge pull request akshitagit#80 from tvibhu12/master
Create filterObject.js
2 parents 4d00942 + 6414720 commit 296538b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Array/FilterObject.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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);

0 commit comments

Comments
 (0)