00:01 - 00:04
let's jump into intellij
00:03 - 00:06
which is the environment we're going to
00:04 - 00:08
be programming programming in
00:06 - 00:10
for the rest of the class and so what
00:08 - 00:12
i'm going to do here is i've just
00:10 - 00:13
created the array of dogs that you did
00:12 - 00:15
in your exercise so it's just this array
00:15 - 00:21
and when i run this it should print out
00:18 - 00:22
an array of dogs such as 20 and 22 but
00:21 - 00:25
as you'll note it's actually just
00:22 - 00:26
printing out all of the array
00:25 - 00:28
so the way that this works the reason
00:26 - 00:30
this is happening is that
00:28 - 00:31
our function larger than four neighbors
00:30 - 00:33
is supposed to return
00:31 - 00:35
only the big dogs the ones that are
00:33 - 00:37
bigger than their four neighbors
00:35 - 00:38
so this is just the code that gets those
00:37 - 00:39
and prints them but right now the
00:38 - 00:43
function simply returns
00:39 - 00:46
dogs so we need it so it returns
00:43 - 00:47
only uh the dogs which are larger than
00:46 - 00:49
their four neighbors
00:47 - 00:50
okay so it's clear that what we need to
00:49 - 00:52
do is something like
00:50 - 00:54
iterate over all the dogs right that
00:52 - 00:56
seems very natural
00:54 - 00:58
but this is a little tricky because i
00:56 - 01:00
need to iterate over the neighbors
00:58 - 01:03
so one way i could do this this may not
01:00 - 01:06
be your first thought but it's like well
01:03 - 01:09
if we do minus 2 to 2
01:06 - 01:11
then this should iterate
01:09 - 01:14
over the neighbors of the dog so for
01:11 - 01:17
example we could call this
01:14 - 01:19
neighbor dog that would be dogs i plus j
01:17 - 01:21
okay now we run into a problem
01:19 - 01:23
immediately we kind of see it here that
01:21 - 01:24
there's like a minus two thing where
01:23 - 01:28
like if this starts at zero
01:24 - 01:30
and this is minus 2 well then it can go
01:28 - 01:32
negative right like this could be a
01:30 - 01:33
negative value in fact if i look at this
01:32 - 01:35
it says there's a potential that the
01:33 - 01:35
array can go out of balance bounce one
01:35 - 01:37
of the things that's great about
01:35 - 01:38
intellij is it warns you about things
01:37 - 01:39
like this but
01:38 - 01:41
i don't know yeah so it's something i
01:39 - 01:43
need to deal with so i could do
01:41 - 01:48
something like if
01:43 - 01:51
i plus j is less than zero
01:48 - 01:54
then what should we do well
01:51 - 01:55
actually what we should do is i guess we
01:54 - 01:58
are going to
01:55 - 01:59
um continue right we're too early so
01:58 - 02:01
we're just going to say that
01:59 - 02:03
and continue along okay so if at least
02:01 - 02:05
handled we go off the array on the other
02:05 - 02:09
okay but then we also of course have the
02:07 - 02:12
issue like what if it's greater than
02:09 - 02:13
or equal to dogs.length okay well in
02:13 - 02:18
uh i guess we can well we're at the end
02:17 - 02:20
of this loop right we don't need to be
02:18 - 02:21
iterating anymore so i can say break
02:20 - 02:23
and so i have this code here to
02:21 - 02:25
basically handle going out of bounds
02:23 - 02:26
okay already this code is getting pretty
02:26 - 02:29
and helper functions are going to make
02:28 - 02:30
our life easier but let's just keep
02:29 - 02:33
trying to write it okay
02:30 - 02:34
so now we get the neighbor dog um what
02:33 - 02:38
do we do now that we have this neighbor
02:34 - 02:40
dog i guess what we can do is
02:41 - 02:46
well the pattern might be something like
02:43 - 02:48
this i'm going to say boolean
02:46 - 02:51
let's say largest and by default we'll
02:48 - 02:53
say that by that we are the largest dog
02:51 - 02:55
but if it's ever the case that the
02:53 - 03:00
neighbor dog's weight in pounds is
02:55 - 03:00
greater than or equal to um
03:00 - 03:06
dogs dot or let's see dogs i
03:04 - 03:08
that's the current dog that weight in
03:08 - 03:15
then we will say largest equals false
03:12 - 03:19
okay um and then
03:15 - 03:21
once we get to the end so here in theory
03:19 - 03:23
what all this code does is when it's
03:21 - 03:28
done the largest value is true
03:23 - 03:29
only if the current dog is the biggest
03:28 - 03:31
now there's actually one other little
03:29 - 03:33
bug that i've spotted here that i like
03:31 - 03:37
you may not have noticed which is like
03:33 - 03:38
what if uh j is equal to zero
03:37 - 03:40
we don't wanna compare the neighbor dog
03:38 - 03:43
to ourself because you know like
03:40 - 03:45
we're gonna be greater than or equal to
03:43 - 03:48
ourself so we actually also need to say
03:45 - 03:49
for j equals zero uh we should continue
03:48 - 03:51
and that code's getting complicated then
03:49 - 03:54
we still have to do more work
03:51 - 03:54
now i think this is all just a little
03:54 - 03:58
and the problem is that we were just
03:56 - 04:00
trying to like
03:58 - 04:01
make it up as we went along and we ended
04:00 - 04:04
up with something that is
04:01 - 04:05
you know i'd say a little clumsy okay we
04:04 - 04:07
can make this work
04:05 - 04:08
but let's try again okay so that's the
04:07 - 04:09
end of this video this is me trying to
04:09 - 04:14
without thinking about a strategy
04:12 - 04:15
without thinking about a specific
04:14 - 04:17
thing i'd like to do i just started
04:15 - 04:17
writing code and i ended up with special
04:17 - 04:21
and it being a little complicated and a
04:20 - 04:23
dangerous way to go
04:21 - 04:26
so next video we're going to start all
04:23 - 04:26
over and do it differently