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
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
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
OK, hopefully you had some success in putting this remove card method together, so again, I really
think that we're going to end up using this remove where method that belongs to all lists that are created.
So let's go back over to Darte Pad and we're going to put this thing together.
OK, so back over here, I'm going to create a new method inside of my class and I'm going to call it
remove card.
Now, to specify the card that we want to remove, I'm going to expect that we're probably going to
have to pass in the suit in the rank of the card that we're looking for.
So I will receive those as arguments.
I'll say string.
Suits and string rank, if you flip the order of these two arguments right here, that's totally fine,
you can go in absolutely whatever, whatever order you wish.
Then inside of here, I'm going to call that remove where method right here.
Now, one thing that I want to make really clear here, because this is something that might have tripped
you up just a little bit.
It just a couple of seconds ago, we were talking about how lists contain references to objects.
So in this case, when we call it remove where whatever past that truth or false test is going to be
simply removed entirely from the list.
So, like that reference gets deleted.
So we don't have to create a second list or worry about these copying over or anything like that by
just calling remove where it will remove that record from the list.
It doesn't actually delete the original record, but we don't have to actually worry about that.
We just care about removing the record from the list.
All right, so going to go back over to darte pad.
And inside of here, I'm going to call cards dot remove where?
Now, as soon as I add that in, you'll notice that I get the function signature right here, so the
removal, their function should receive a function of its own.
I'm going to get called that thing with a card element, and I'm supposed to return a boolean from it.
So I'll place my set of parentheses and then inside of here, I'm going to first get started by using
that long form syntax for defining a function.
You'll recall that back up here, we use the shorthand syntax with the arrow function, with the arrow
symbol right there.
But this time around, I'm just going to start easy and assume that I might need the long form syntax.
So I will receive a card inside this thing.
And then from this function, I'm going to return.
Card, dot suit.
So this is the suit that belongs to the card that we're currently iterating over and I'm going to check
to see if that is equal to the suit that was passed into our function.
So if these two values right here are identical, then that means that this is probably a card that
I want to remove.
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
like so.
This right here might have been a little bit of a reach.
I apologize, I didn't really tell you about how to combine boolean values together.
So if this part right here of getting kind of combining two boolean values together was confusing,
I do apologize for that.
And then for the second comparison, I want to make sure that we had the same rank as well.
We'll say car rank equals equals and then rank.
Now, just to add a little bit of clarity in the order of operations of how this entire boolean statement
gets resolved, I might choose to add a set of parentheses around each of those comparisons.
It is not necessary, but we could definitely do so just to make the order there a little bit more clear.
OK, so I think this might be a working implementation here.
Remember, when we call remove where like we were saying just a second ago, that modifies our existing
list.
It doesn't return a new list or anything like that.
It modifies the existing list that we're looking at.
So we don't have to worry about kind of reassigning over our cards, property or anything like that.
OK, so I'm going to test this out by going up to the top of the file.
Here's my main function, I'm going to remove the print statements that we have right now.
I'm going to call the Dec dot remove card method.
As a first argument, I'm going to pass in a suit, so I'm going to try to delete this ace of diamonds
right here, so the suit that I'm going to try to delete is going to be diamonds.
And then the rank will be a.
And then after I removed that card, I'll print the deck out and I'll just verify that the ace of diamonds
is no longer inside their.
OK, so, Arun.
And OK, that looks great, so we no longer have the two or the ace of diamonds in there and our deck
starts off first with the two of diamonds.
Now, the last thing I might want to consider.
Is to refactor this long form syntax right here into a single arrow function, as we had done previously
with the cards with suit method.
Now, this would definitely be a candidate for that refactor, because we have a single expression here,
even though it looks like we're doing multiple operations, it's still overall a single expression.
It doesn't span multiple separate lines of code.
So I could do a little bit of a refactor.
By removing the return keyword, removing the semicolon.
Removing the curly braces.
And then putting an arrow inside of here with equals and then a greater than sine.
All right, so that should definitely be appropriate or equivalent.
You'll notice that it kind of looks like it gets scrunched up onto two lines there.
You might see something.
It looks a little bit more like that, which looks a lot better.
But like I said, the two are one hundred percent equivalent, so it's really up to you which way you
want to go.
I'm going to run this one more time just to make sure that refactored did not break my code.
And in fact, it looks like we're good to go.
OK, so that's pretty much it for, ah, deck class.
So we've gotten a better sense of how classes work and we've also done a real deep dive on some of the
documentation around lists and gotten a better idea of how references work.
And there's still a ton of stuff for us to learn about darte.
So let's take a quick break and continue in the next section.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.