-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranscript.txt
More file actions
269 lines (269 loc) · 5.02 KB
/
Copy pathtranscript.txt
File metadata and controls
269 lines (269 loc) · 5.02 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
example 1
0:00
hey again everybody it's me big surprise
0:02
there today I'm going to explain the
0:03
filter method in JavaScript the filter
0:06
method creates a new array by filtering
0:09
out elements in this example we'll
0:11
create an array of
0:13
numbers we will filter out any numbers
0:16
that are odd let's add the numbers 1
0:19
through
0:22
7 now we need a
0:24
function
0:25
function is even we have one parameter
0:29
we have an element that's going to be
0:31
provided to us by the filter method we
0:34
are going to return then write a
0:36
condition we will take our element
0:40
modulus 2 the modulus operator gives you
0:43
the remainder of any division you can
0:45
use modulus 2 to check to see if a
0:47
number is even if this condition is zero
0:50
strictly equal to zero then we will
0:53
return true we will be returning a
0:56
Boolean true or false the filter method
0:59
will will take any values that return
1:01
true and stick them within a new array
1:04
which will effectively filter out any
1:05
elements we don't need that don't return
1:07
true let's see if this works I will
1:09
create a new array even nums equals take
1:14
our original array use the filter method
1:18
pass in a call back is even we will
1:23
display
1:25
console.log our new array even numbers
1:29
and there we are
1:30
2 4 6 let's do this with odd
1:34
numbers function is
1:38
odd take our element modulus 2 is this
1:42
strictly not equal to zero that means
1:46
the number is
1:47
odd let's create a new array let odd
1:51
nums equals our original array numbers
1:56
do use the filter method passing a call
1:58
back is odd let's check out our new
2:02
array odd
2:04
nums there we are we have the numbers 1
2:07
35 7 any numbers that are odd let's go
2:11
over another
2:12
example I will create an array of Ages
example 2
2:15
I'll use const this time instead of let
2:17
const ages Pretend We're teaching a
2:21
college class we might have some
2:23
students still in high school let's say
2:24
a student is 16 another is 17 two are 18
2:30
19 20 and then we have somebody that's
2:33
just a little bit older they're um 60
2:36
we'll use the filter method to filter
2:38
out anybody that is under 18 we will
2:40
find all of the adults we will need a
2:43
function function is adult we have one
2:48
element as a parameter that's going to
2:50
be provided to us we will return a
2:55
condition return check our element is it
2:59
great greater than or equal to
3:02
18 so that's our function let's create a
3:06
new array of adults equals take our
3:10
original array dot use the filter method
3:14
pass in a call back is adult then
3:18
display our new array
3:20
console.log
3:22
adults we have five elements the age of
3:25
the students is 18 18 19 20 and 60 let's
3:30
do this with is children to find anybody
3:33
that's under
3:34
18 is child
3:37
function return element less than 18
3:42
we'll create a new array const children
3:47
equals take our original array use the
3:50
filter method pass in a call back is
3:53
child then display the new array we have
3:57
two students that are children one is 16
4:00
the other is 17 last example we'll
example 3
4:03
create an array of words const
4:07
words add some words I think I'll add
4:10
some fruit I'll add an
4:13
apple
4:15
orange
4:17
banana
4:20
kiwi
4:24
pomegranate and a
4:27
coconut I will filter out any words
4:30
where the length of that word is above
4:32
six so we will create a function
4:35
function get short
4:39
words we have an element as a
4:42
parameter we will return a condition we
4:46
will check if our element access the
4:49
length property of that element they're
4:51
strings so they all have a length
4:53
property how many characters are they
4:55
long that's the length check to see if
4:57
the length of this element is less than
5:00
or equal to
5:01
six if it is return true if not return
5:05
false we will create a new array let's
5:08
call this array short words equals take
5:12
our array use the built-in filter method
5:16
pass in a call back get short words then
5:19
we will console.log the new array short
5:23
words in our array there are four
5:26
elements with the length of the
5:27
characters of each string is six
5:29
surrender Apple orange banana kiwi then
5:33
to finish this off let's get any long
5:35
words we'll create a new
5:37
function get long words check the length
5:41
of the element to see if it's above six
5:45
then we will create a new array const
5:48
long words equals take our original
5:51
array use the filter method pass in a
5:54
call back get long words then we will
5:57
display our new array long words within
6:01
our original array there's two words
6:03
that are considered long pomegranate and
6:05
coconut these words each have more than
6:07
six characters coconut is seven
6:11
pomegranate is 11 all right everybody
6:14
that is the filter method it creates a
6:16
new array by filtering out elements your
6:19
callback is likely going to check in
6:21
condition does each element pass this
6:23
condition and well everybody that is the
6:25
filter method in
6:28
JavaScript