Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,810 --> 00:00:06,240
OK, hopefully you had some success in putting this remove card method together, so again, I really
2
00:00:06,240 --> 00:00:11,580
think that we're going to end up using this remove where method that belongs to all lists that are created.
3
00:00:12,190 --> 00:00:14,930
So let's go back over to Darte Pad and we're going to put this thing together.
4
00:00:16,210 --> 00:00:22,330
OK, so back over here, I'm going to create a new method inside of my class and I'm going to call it
5
00:00:22,330 --> 00:00:23,320
remove card.
6
00:00:25,140 --> 00:00:29,130
Now, to specify the card that we want to remove, I'm going to expect that we're probably going to
7
00:00:29,130 --> 00:00:32,549
have to pass in the suit in the rank of the card that we're looking for.
8
00:00:33,280 --> 00:00:35,610
So I will receive those as arguments.
9
00:00:36,060 --> 00:00:37,380
I'll say string.
10
00:00:38,500 --> 00:00:44,740
Suits and string rank, if you flip the order of these two arguments right here, that's totally fine,
11
00:00:44,740 --> 00:00:47,710
you can go in absolutely whatever, whatever order you wish.
12
00:00:48,850 --> 00:00:54,130
Then inside of here, I'm going to call that remove where method right here.
13
00:00:54,640 --> 00:00:58,120
Now, one thing that I want to make really clear here, because this is something that might have tripped
14
00:00:58,120 --> 00:00:59,170
you up just a little bit.
15
00:00:59,530 --> 00:01:04,480
It just a couple of seconds ago, we were talking about how lists contain references to objects.
16
00:01:04,930 --> 00:01:12,040
So in this case, when we call it remove where whatever past that truth or false test is going to be
17
00:01:12,040 --> 00:01:14,860
simply removed entirely from the list.
18
00:01:15,340 --> 00:01:17,290
So, like that reference gets deleted.
19
00:01:18,220 --> 00:01:22,900
So we don't have to create a second list or worry about these copying over or anything like that by
20
00:01:22,900 --> 00:01:26,380
just calling remove where it will remove that record from the list.
21
00:01:26,560 --> 00:01:30,810
It doesn't actually delete the original record, but we don't have to actually worry about that.
22
00:01:30,970 --> 00:01:33,880
We just care about removing the record from the list.
23
00:01:34,950 --> 00:01:37,380
All right, so going to go back over to darte pad.
24
00:01:38,330 --> 00:01:42,560
And inside of here, I'm going to call cards dot remove where?
25
00:01:43,700 --> 00:01:48,710
Now, as soon as I add that in, you'll notice that I get the function signature right here, so the
26
00:01:48,710 --> 00:01:52,010
removal, their function should receive a function of its own.
27
00:01:52,950 --> 00:01:58,890
I'm going to get called that thing with a card element, and I'm supposed to return a boolean from it.
28
00:01:59,780 --> 00:02:04,550
So I'll place my set of parentheses and then inside of here, I'm going to first get started by using
29
00:02:04,550 --> 00:02:07,350
that long form syntax for defining a function.
30
00:02:07,850 --> 00:02:12,950
You'll recall that back up here, we use the shorthand syntax with the arrow function, with the arrow
31
00:02:12,950 --> 00:02:13,730
symbol right there.
32
00:02:13,820 --> 00:02:18,770
But this time around, I'm just going to start easy and assume that I might need the long form syntax.
33
00:02:19,900 --> 00:02:22,150
So I will receive a card inside this thing.
34
00:02:23,030 --> 00:02:25,460
And then from this function, I'm going to return.
35
00:02:26,430 --> 00:02:28,870
Card, dot suit.
36
00:02:29,010 --> 00:02:33,600
So this is the suit that belongs to the card that we're currently iterating over and I'm going to check
37
00:02:33,600 --> 00:02:37,920
to see if that is equal to the suit that was passed into our function.
38
00:02:38,580 --> 00:02:43,380
So if these two values right here are identical, then that means that this is probably a card that
39
00:02:43,380 --> 00:02:44,250
I want to remove.
40
00:02:45,100 --> 00:02:50,740
And then to check to see if I also want to remove the rank as well, I'm going to add in and and and
41
00:02:50,770 --> 00:02:51,340
like so.
42
00:02:52,370 --> 00:02:55,200
This right here might have been a little bit of a reach.
43
00:02:55,220 --> 00:02:59,240
I apologize, I didn't really tell you about how to combine boolean values together.
44
00:02:59,400 --> 00:03:03,830
So if this part right here of getting kind of combining two boolean values together was confusing,
45
00:03:03,830 --> 00:03:05,090
I do apologize for that.
46
00:03:06,150 --> 00:03:10,080
And then for the second comparison, I want to make sure that we had the same rank as well.
47
00:03:10,660 --> 00:03:14,370
We'll say car rank equals equals and then rank.
48
00:03:15,990 --> 00:03:20,850
Now, just to add a little bit of clarity in the order of operations of how this entire boolean statement
49
00:03:20,850 --> 00:03:26,340
gets resolved, I might choose to add a set of parentheses around each of those comparisons.
50
00:03:27,060 --> 00:03:32,250
It is not necessary, but we could definitely do so just to make the order there a little bit more clear.
51
00:03:33,530 --> 00:03:36,870
OK, so I think this might be a working implementation here.
52
00:03:37,250 --> 00:03:43,070
Remember, when we call remove where like we were saying just a second ago, that modifies our existing
53
00:03:43,070 --> 00:03:43,520
list.
54
00:03:43,520 --> 00:03:45,440
It doesn't return a new list or anything like that.
55
00:03:45,590 --> 00:03:48,350
It modifies the existing list that we're looking at.
56
00:03:48,350 --> 00:03:53,360
So we don't have to worry about kind of reassigning over our cards, property or anything like that.
57
00:03:54,750 --> 00:03:58,050
OK, so I'm going to test this out by going up to the top of the file.
58
00:03:59,740 --> 00:04:03,760
Here's my main function, I'm going to remove the print statements that we have right now.
59
00:04:04,710 --> 00:04:08,880
I'm going to call the Dec dot remove card method.
60
00:04:09,760 --> 00:04:14,020
As a first argument, I'm going to pass in a suit, so I'm going to try to delete this ace of diamonds
61
00:04:14,020 --> 00:04:17,920
right here, so the suit that I'm going to try to delete is going to be diamonds.
62
00:04:19,019 --> 00:04:20,519
And then the rank will be a.
63
00:04:22,950 --> 00:04:28,140
And then after I removed that card, I'll print the deck out and I'll just verify that the ace of diamonds
64
00:04:28,140 --> 00:04:29,340
is no longer inside their.
65
00:04:30,180 --> 00:04:31,110
OK, so, Arun.
66
00:04:33,350 --> 00:04:38,480
And OK, that looks great, so we no longer have the two or the ace of diamonds in there and our deck
67
00:04:38,480 --> 00:04:40,650
starts off first with the two of diamonds.
68
00:04:41,480 --> 00:04:43,370
Now, the last thing I might want to consider.
69
00:04:44,420 --> 00:04:50,720
Is to refactor this long form syntax right here into a single arrow function, as we had done previously
70
00:04:50,720 --> 00:04:52,520
with the cards with suit method.
71
00:04:53,350 --> 00:04:58,150
Now, this would definitely be a candidate for that refactor, because we have a single expression here,
72
00:04:58,510 --> 00:05:03,270
even though it looks like we're doing multiple operations, it's still overall a single expression.
73
00:05:03,520 --> 00:05:05,980
It doesn't span multiple separate lines of code.
74
00:05:06,580 --> 00:05:08,680
So I could do a little bit of a refactor.
75
00:05:09,590 --> 00:05:13,130
By removing the return keyword, removing the semicolon.
76
00:05:14,210 --> 00:05:15,830
Removing the curly braces.
77
00:05:18,250 --> 00:05:22,570
And then putting an arrow inside of here with equals and then a greater than sine.
78
00:05:23,930 --> 00:05:27,810
All right, so that should definitely be appropriate or equivalent.
79
00:05:28,160 --> 00:05:32,300
You'll notice that it kind of looks like it gets scrunched up onto two lines there.
80
00:05:32,480 --> 00:05:33,380
You might see something.
81
00:05:33,380 --> 00:05:35,830
It looks a little bit more like that, which looks a lot better.
82
00:05:36,750 --> 00:05:40,140
But like I said, the two are one hundred percent equivalent, so it's really up to you which way you
83
00:05:40,140 --> 00:05:40,620
want to go.
84
00:05:40,950 --> 00:05:44,490
I'm going to run this one more time just to make sure that refactored did not break my code.
85
00:05:44,910 --> 00:05:46,590
And in fact, it looks like we're good to go.
86
00:05:47,190 --> 00:05:50,880
OK, so that's pretty much it for, ah, deck class.
87
00:05:51,330 --> 00:05:56,910
So we've gotten a better sense of how classes work and we've also done a real deep dive on some of the
88
00:05:56,910 --> 00:06:00,660
documentation around lists and gotten a better idea of how references work.
89
00:06:01,230 --> 00:06:04,110
And there's still a ton of stuff for us to learn about darte.
90
00:06:04,110 --> 00:06:06,960
So let's take a quick break and continue in the next section.
9165
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.