forked from jsd20191008/countries-iterators-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pset-iterators.js
201 lines (135 loc) · 4.48 KB
/
pset-iterators.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
Instructions:
For this problem set you will be working with a
list of Countries stored as an array of
objects. The array has **already been provided for
you** as a variable named "countries".
You can see the full list of us countries in the
provided file named `countries.js`
All of the following problems require that you
use the `countries` array to solve them.
Use any variables or methods deemed necessary
to solve each problem.
You can use either regular functions or
arrow functions for your callbacks
*/
const countries = require('./countries.js') // <- DO NOT Remove; this represents an array consisting of countries
/***********
Sample Problem:
1. Using the `countries` array, return the **name** of the
first country that was listed that is located in South America.
Save the data in a variable called `firstListedSouthAmericanCountry`,
declared with const
2. Print `firstListedSouthAmericanCountry` to the console
************/
console.log('Sample Problem:')
// Add your code below this line
const firstListedSouthAmericanCountry = countries.find(function (country) {
return country.continentName === 'South America'
})
console.log(firstListedSouthAmericanCountry.countryName)
// Add your code above this line
/** added for formatting purposes **/
console.log('')
console.log('-----------------')
/***********
Problem 1:
1. Using the `countries` array,
return a list (an array) of all the
countries that have names that begin with a "c".
Save the data in a variable called `countriesWithNamesStartingWithC`,
declared with const
2. Print `countriesWithNamesStartingWithC` to the console
************/
console.log('Problem 1:')
// Add your code below this line
// Add your code above this line
/** added for formatting purposes **/
console.log('')
console.log('-----------------')
/***********
Problem 2:
1. Using the `countries` array, return a list (an array) of just the "name" of every country in the world.
Save the data in a variable called `allCountryNames`,
declared with const
2. Print `allCountryNames` to the console
************/
console.log('Problem 2:')
// Add your code below this line
// Add your code above this line
/** added for formatting purposes **/
console.log('')
console.log('-----------------')
/***********
Problem 3:
1. Using the `coutries` array, return a
list of the countries that have a population
of less than 1,000,000 people. Save the data in a variable called `smallCountries`, declared with const
2. Print `smallCountries` to the console
************/
console.log('Problem 3:')
// Add your code below this line
// Add your code above this line
/** added for formatting purposes **/
console.log('')
console.log('-----------------')
/***********
Problem 4:
1. Using the `countries` array, return a list of the
countries in Africa
Save the data in a variable called `africanCountries`,
declared with const
2. Print `africanCountries` to the console
************/
console.log('Problem 4:')
// Add your code below this line
// Add your code above this line
/** added for formatting purposes **/
console.log('')
console.log('-----------------')
/***********
Problem 5:
1. Using the `countries` array,
return the name of the all countries that
list english ("en") as one of their
official languages
Save the data in a variable
called `englishSpeakingCountries`, declared with const
2. Print `englishSpeakingCountries` to the console
************/
console.log('Problem 5:')
// Add your code below this line
// Add your code above this line
/** added for formatting purposes **/
console.log('')
console.log('-----------------')
/***********
Problem 6:
1. Using the `countries` array,
return the name of the all countries that
have 4 or more official languages
Save the data in a variable
called `countriesWithFourOrMoreLanguages`, declared with const
2. Print `countriesWithFourOrMoreLanguages` to the console
************/
console.log('Problem 6:')
// Add your code below this line
// Add your code above this line
/** added for formatting purposes **/
console.log('')
console.log('-----------------')
/***********
Problem 7:
1. Using the `countries` array,
return the average population of all of
the countries in South America
Save the data in a variable
called `avgPopulationOfSouthAmericanCountries`, declared with const
2. Print `avgPopulationOfSouthAmericanCountries` to the console
************/
console.log('Problem 7:')
// Add your code below this line
// Add your code above this line
/** added for formatting purposes **/
console.log('')
console.log('-----------------')