Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
1 1
Welcome back to the first coding challenge 2
2
of the arrays section. 3
3
And in this one, Julia and Kate are doing a study on dogs. 4
4
So each of them asked five dog owners about their dog's age 5
5
and then they stored that data into an array. 6
6
And that's one array for each of them. 7
7
All right? 8
8
And in this study, they are interested in knowing 9
9
whether each of the dogs is an adult or a puppy. 10
10
And the rule is that a dog is an adult 11
11
if it is at least three years old, 12
12
and it's a puppy if it's less than three years old. 13
13
And by the way, the test data here, 14
14
so the arrays for it is down here. 15
15
So test data one and two. 16
16
All right? 17
17
So, your task is to create a function called check dogs, 18
18
which accepts these two arrays 19
19
and does the following things. 20
20
So first, Julia found out that the owners of the first 21
21
and the last two dogs do actually have cats and not dogs. 22
22
So here, what I want you to do 23
23
is to create a shallow copy of Julia's array 24
24
and then remove the cat ages from the copied array. 25
25
And you should copy it because it's a bad practice 26
26
to mutate the parameters or the arguments of a function. 27
27
Then second, create an array 28
28
with both Julia's and Kate's data. 29
29
So for Julia, of course, the corrected data. 30
30
And then for each of the dogs, 31
31
simply log to the console whether it is an adult 32
32
with a string like this 33
33
or a puppy and then with a string like this. 34
34
And that's, of course, according to the rules 35
35
in the beginning. 36
36
And then, just run this function for both test data sets. 37
37
And that's it. 38
38
So all you need to do is to use the tools 39
39
from all the lectures in this section so far 40
40
and then I think you will be fine solving this on your own. 41
41
So this is really all about using the tools 42
42
that we already learned before 43
43
and there's not a lot of new thinking to do here. 44
44
So I hope you manage to do this one. 45
45
And I see you back here in a second. 46
46
All right. 47
47
So hopefully, you did this just fine without any problems 48
48
but I will anyway write my solution here 49
49
and explain what I am doing. 50
50
So, we accept the dogs from Julia 51
51
and the dogs from Kate. 52
52
And we will call this with the test data. 53
53
And so, Julia's data is this 54
54
and there's not a need to store them in separate variables. 55
55
I will just call the function like this. 56
56
All right? 57
57
And now we should create a shallow copy of dogs Julia, 58
58
so that we can then remove some elements from there. 59
59
So dogsJuliaCorrected.slice 60
60
So dogsJuliaCorrected.slice 61
61
and so I'm using here the method 62
62
and not the spread operator. 63
63
And now, I will simply remove some elements from there. 64
64
So dogsJuliaCorrected.splice 65
65
and so, it tells us that the first 66
66
and the last two dogs are not valid basically. 67
67
So, the first is element number zero 68
68
and then we want to remove one. 69
69
So that's the first part. 70
70
And then dogsJuliaCorrected.splice 71
71
and then the last two, which is minus two. 72
72
Okay? 73
73
So, let's take a look here simply at 74
74
dogsJuliaCorrected just to see 75
75
if this is correct actually. 76
76
So we need the console now. 77
77
And so this was or beginning data and indeed, 78
78
the first and the last two are done here. 79
79
All right? 80
80
Now, of course, you could have also done this 81
81
in a different way, 82
82
which is to simply copy the correct data 83
83
from the original using the slice method. 84
84
So something like this: dogsJulia.slice, 85
85
So something like this: dogsJulia.slice, 86
86
so starting from the second one 87
87
and then all the way to the third one. 88
88
Okay, and so this would give us the exact same result 89
89
but in this case, I just wanted to use the splice method. 90
90
And, in fact, I wanted you to use the splice method as well 91
91
and that's why I gave you that task like that. 92
92
Anyway, we don't need this here anymore. 93
93
Let's now simply create a new variable with both these dogs. 94
94
So simply calling it dogs. 95
95
And again, we could use the spread operator here 96
96
which I actually prefer 97
97
but since we are in the arrays section here, 98
98
let's do everything with array methods. 99
99
So that's the concat method, remember? 100
100
And then we want to join 101
101
the corrected Julia dogs with dogs Kate. 102
102
So always a good idea to check. 103
103
And yeah, that's correct. 104
104
All right? 105
105
And so, all we have to do now is 106
106
basically create this string. 107
107
Let me just copy this string. 108
108
And so, looping over this array is now an easy task. 109
109
Hopefully. 110
110
So dogs.forEach 111
111
then the callback function 112
112
and one more time, 113
113
we need actually the current element and also the index. 114
114
And that's because here is the number. 115
115
So dog number one and it's going to go all the way to seven. 116
116
And so, let's check out our rule. 117
117
So, a dog is an adult if he is at least three years old. 118
118
So if dog is greater equal three, 119
119
then log a string like this. 120
120
So here is the index plus one. 121
121
Here goes the dog itself 122
122
and then else 123
123
is still a puppy. 124
124
And here we need just this. 125
125
And, I think, with this we are good. 126
126
Just remove this. 127
127
And yes, dog number one is five years old, 128
128
so it's still an adult. 129
129
Number two is two years old, so still a puppy. 130
130
This is again a puppy with one year old 131
131
and so, yeah, that's the correct solution. 132
132
Now let's just do it for this test data here. 133
133
Gonna duplicate this one. 134
134
Let's just comment out the first one 135
135
and okay, here we only have one puppy 136
136
which is the one before the last. 137
137
And so this one is correct as well. 138
138
And so, challenge completed.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.