Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 89c3279

Browse files
Create filterArray.js
1 parent 12bbb22 commit 89c3279

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎Javascript/filterArray.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
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.
3+
4+
5+
Note: City name can be in lower case too. ex - bangalore, gwalior.
6+
*/
7+
8+
function filterByCity(arr) {
9+
10+
arr = arr.filter(data => {
11+
return data.city.toLowerCase() === "bangalore" ||
12+
data.city.toLowerCase() === "hyderabad"
13+
})
14+
15+
return arr;
16+
}
17+
18+
19+
arr = [
20+
{ name: "John", city: "delhi" },
21+
{ name: "Peter", city: "bangalore" },
22+
{ name: "Mike", city: "Bangalore" },
23+
{ name: "Rachel", city: "Hyderabad" }
24+
25+
]
26+
console.log(filterByCity(arr));
27+
module.exports = filterByCity;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /