-
Notifications
You must be signed in to change notification settings - Fork 10
/
objectIteration.js
65 lines (60 loc) · 1.96 KB
/
objectIteration.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const cities = [
{
id: 301,
name: "New York",
population: 8398748,
country: "United States",
},
{
id: 302,
name: "Paris",
population: 2140526,
country: "France",
},
{
id: 303,
name: "Tokyo",
population: 13960000,
country: "Japan",
},
{
id: 304,
name: "Sydney",
population: 5230330,
country: "Australia",
},
{
id: 305,
name: "Cairo",
population: 9121515,
country: "Egypt",
},
];
// 1) Write a `getCityPopulation` function that accepts `city` object argument, return the population of that city
function getCityPopulation(city) {
// write your code here...
}
// console.log(getCityPopulation(cities[0])); // Outputs: 8398748
// 2) Write a `isPopulationAboveThreshold` function that accepts the following arguments `city` object and `threshold` number, return true if the city's population is greater than or equal to the threshold, otherwise returns false
function isPopulationAboveThreshold(city, threshold) {
// write your code here...
}
// console.log(isPopulationAboveThreshold(cities[1], 2000000)); // Outputs: true
// 3) Write a `addCity` function that accepts the following argument, an array of city object `cities` and the properties of a city (id, name, population, and country).
// Create a new city object and add it to the end of the array.
// Return the updated array of cities
function addCity(cities, id, name, population, country) {
// write your code here...
}
// console.log(addCity(cities, 306, "Vancouver", 1200000, "Canada" ));
// 4) Write a `countCitiesInCountry` function that accepts the following arguments, an array of city objects `cities` and `country` string, return the number of cities in the specified country
function countCitiesInCountry(cities, country) {
// write your code here...
}
// console.log(countCitiesInCountry(cities, "France")); // Outputs: 1
module.exports = {
getCityPopulation,
isPopulationAboveThreshold,
addCity,
countCitiesInCountry,
};