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
English
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
In this lecture, 2
2
we're gonna talk about solving problems. 3
3
Solving problems is one of the most important things 4
4
in programming. 5
5
So if your goal is to become a great programmer, 6
6
you need to learn how to deal with problems effectively. 7
7
So in this video, I will show you how to think 8
8
as a developer by solving problems, 9
9
using a simple four step framework. 10
10
And let's use our friend John again. 11
11
So, after some time John can code now, 12
12
he is almost job ready at this point, 13
13
but he still needs to work on his problem solving skills. 14
14
And in programming, when we say solving problems 15
15
we mean a real problem that needs a real solution. 16
16
For example, in an array or GPS coordinates, 17
17
find the two closest to points. 18
18
And this problem is not straight forward, right? 19
19
There are a lot of steps involved in solving this. 20
20
And so we need a way to effectively solve problems 21
21
like this one, or even way more complex ones. 22
22
So problem solving does not mean to fix coding mistakes 23
23
or bucks, all right? 24
24
Anyway, whenever John encounters a problem 25
25
that he needs to solve, 26
26
he usually just jumps at the problem without much thinking. 27
27
He also implements his solutions in an unstructured way 28
28
without much of a logical approach. 29
29
This makes him stressed out 30
30
when things don't work right away. 31
31
Another problem that John has, 32
32
is that he is too proud to research 33
33
when he doesn't know how to come up with his own solution. 34
34
So, all of this is not effective at all, 35
35
and makes John waste a lot of time. 36
36
Now, the first fix to this is to always stay calm 37
37
and slow down and not just jump at a solution 38
38
without having a plan. 39
39
Also, when solving problems, 40
40
you need to be in a mindset 41
41
of taking a logical and rational approach, 42
42
after all programming is just logic, all right? 43
43
Then when you are in the right mindset, 44
44
just use my four step framework 45
45
to solve the problem at hand. 46
46
And the first step of the framework 47
47
is to make sure that you 100% understand the problem. 48
48
Step back and take a high-level look at the big picture. 49
49
And the most important part of the step 50
50
is to ask the right questions 51
51
in order to get a clear picture of the whole problem. 52
52
And the best way of understanding this, 53
53
is probably to look at an example together here. 54
54
So let's say you are working at some company 55
55
on some project, 56
56
and then your project manager comes and tells you, 57
57
"We need a function that reverses, 58
58
"whatever we pass into it." 59
59
And that's all you know about the problem, 60
60
but do you understand it 100%? 61
61
Well, probably not, right? 62
62
I know that I don't. 63
63
So let's ask the right questions to get there. 64
64
First we can ask, 65
65
what does whatever actually mean in this context? 66
66
So, what should actually be reversed here? 67
67
Well, and if we think about it, 68
68
it only makes sense to reverse strings, 69
69
numbers, and arrays. 70
70
Objects don't have a well-defined order, 71
71
so we can't reverse them. 72
72
We're also not gonna reverse like undefined, 73
73
or null or a Boolean, right? 74
74
Then after we have that figured out, 75
75
we can ask, what should we do if something else 76
76
is passed in that is no string, number, or array? 77
77
How are we gonna handle that? 78
78
It's also relevant to ask, 79
79
what exactly should be returned from the function? 80
80
For example, should it always be a string, 81
81
or should the tie be the same as was passed in? 82
82
Well, in this case, probably we should always 83
83
just returned the exact same type that was passed in. 84
84
Also we can start to ask more solution oriented questions, 85
85
like how to recognize whether the argument is a number, 86
86
a string, or an array? 87
87
Or how to actually it reverse a number, 88
88
a string and an array. 89
89
So these are just some of the questions 90
90
that we can ask here. 91
91
I'm sure there are more, 92
92
but this should already give us 93
93
a way more clear picture of this problem. 94
94
Now, right now, at the beginning of your journey, 95
95
you were probably not yet know, 96
96
what the right questions actually are, but don't worry, 97
97
this will come with time and practice I promise. 98
98
The next step is probably the most important one, 99
99
which is the divide and conquer strategy. 100
100
Divide and conquer means to break up the big problem 101
101
into as many small problems as possible 102
102
because these small problems are then a lot easier to solve. 103
103
And this also ties in with the previous step 104
104
because by dividing the problem into sub problems, 105
105
you also take the big problem apart, 106
106
until you understand it exactly. 107
107
So based on the previous step, 108
108
if we wanted to break down this problem, 109
109
we could define a couple of sub problems. 110
110
First, we need to check if the argument 111
111
is a number, a string, or an array. 112
112
And this is in fact, a small sub problem, right? 113
113
So now, and just solve this one 114
114
in isolation and then move on. 115
115
The next sub problem is to implement reversing a number, 116
116
then implement reversing a string, 117
117
and then implement reversing an array, 118
118
so that we are ready to deal 119
119
whatever is passed into the function. 120
120
Finally, we then also need of course 121
121
to return the reversed value. 122
122
So these are our sub problems, 123
123
and they kind of look like a task list 124
124
that we now need to go ahead and implement. 125
125
And this is great because it makes our work 126
126
so much easier now. 127
127
Now, sure, this example is a pretty simple problem, 128
128
but this strategy works just as well 129
129
for bigger and way more complex problems. 130
130
In fact, divide and conquer isn't essential method 131
131
of problem solving that is also used a lot 132
132
outside of programming. 133
133
Anyway, with this, we have actually already covered 134
134
the two most important steps of the framework. 135
135
But now let's say that we actually do not know 136
136
how to implement one of these sub problems. 137
137
Well, in that case, we should not be afraid 138
138
of doing as much research as we have to. 139
139
Now, of course, we should always first try 140
140
to implement a sub problem on our own 141
141
using our own coding abilities. 142
142
But if we're constantly hitting a wall, 143
143
and cannot move on, then we should waste no more time 144
144
and just find out how it works using Google, 145
145
or a questions and answers websites 146
146
like Stack Overflow, or the MDN JavaScript documentation. 147
147
We will see how to use these in the next lecture 148
148
when we're gonna work together on a real problem. 149
149
And actually researching is a huge part 150
150
of a programmer's job, as you will find out very soon. 151
151
So you really should not be ashamed 152
152
when you don't know enough to solve a certain problem. 153
153
Let's just completely normal. 154
154
Now, in this case some questions that we could Google are, 155
155
how to check if a value is a number, 156
156
or an array, or a string in JavaScript. 157
157
Or we could Google how to reverse a number, 158
158
or a string, or an array in JavaScript, okay? 159
159
And again, we will do this in the next lecture 160
160
on a real problem together. 161
161
Finally, in case we are trying to solve bigger problems 162
162
we should put all the previous steps together 163
163
and write some so-called pseudo-code 164
164
before writing the actual code. 165
165
And pseudo-code is simply an informal description 166
166
of the actual code that we're gonna write. 167
167
So it's like code for humans to understand not computers. 168
168
For our example, the pseudo-code 169
169
might look something like this. 170
170
So you see we use some structures of a programming language, 171
171
but this is clearly not JavaScript, right? 172
172
And there are no real rules 173
173
on how to write pseudo-code either, 174
174
you just write so that you understand it yourself, 175
175
or other people on your team. 176
176
So in this example, we just start 177
177
by naming the function as a reverse, 178
178
and then we basically pass in a value. 179
179
Then we say, that if the type of the value 180
180
is not a string and not a number, 181
181
and also not an array, then simply return the value back. 182
182
And that's because as we defined previously, 183
183
we only want dysfunction to work for strings 184
184
or for numbers or for a race. 185
185
And again, you can clearly see 186
186
that this is not any valid JavaScript at all. 187
187
But anyway, if the type of the value past this initial test, 188
188
then we say if the value is a string, 189
189
then reverse the string. 190
190
If the value is a number, then reverse the number. 191
191
And if the value is an array, 192
192
then simply reversed the array. 193
193
And then at the end, 194
194
we want to return to reversed value, okay? 195
195
So this is really more like a list of instructions 196
196
that we now could go ahead and actually implement 197
197
using the JavaScript language. 198
198
Okay, and that's it. 199
199
That's the four steps to solve any problem 200
200
no matter how big. 201
201
And now before I leave you, a final tip I can give you, 202
202
is to develop a genuine curiosity and passion 203
203
for understanding how things actually work, 204
204
not only in programming, 205
205
but really in the whole world around you. 206
206
For example, the famous scientist Richard Feynman, 207
207
was repairing radios when he was just a teenager, 208
208
and Elon Musk made his first computer game when he was 12. 209
209
And there are many more examples like this, 210
210
and all of them became geniuses in their fields 211
211
in part because of their genuine curiosity 212
212
on how the world around them works. 213
213
All right, and with that being said, 214
214
let's now go ahead and solve a real problem 215
215
in the next lecture using this framework 216
216
that we just learned about. 217
217
So I'll see you there.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.