forked from theprogrammedwords/Algorithm-Solutions-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilterArray.js
More file actions
27 lines (19 loc) · 706 Bytes
/
filterArray.js
File metadata and controls
27 lines (19 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
Given an array of objects having properties, name and city. Use JavaScript filter() function to return an array containing objects having either Bangalore or Hyderabad as their city property value.
Note: City name can be in lower case too. ex - bangalore, gwalior.
*/
function filterByCity(arr) {
arr = arr.filter(data => {
return data.city.toLowerCase() === "bangalore" ||
data.city.toLowerCase() === "hyderabad"
})
return arr;
}
arr = [
{ name: "John", city: "delhi" },
{ name: "Peter", city: "bangalore" },
{ name: "Mike", city: "Bangalore" },
{ name: "Rachel", city: "Hyderabad" }
]
console.log(filterByCity(arr));
module.exports = filterByCity;