Transcript
English (Auto-generated)
and welcome back to the learn with me series. I just finished lesson five which was all about lists and elixir. And we have the homework here, which is just to figure out how to do a couple things with lists. Um so I figured I'd do this one live, I didn't do part four lives because it was a lot lengthier and there was an article to read beforehand. So I figured the cast would be a little bit too long for it to be interesting. But I did actually go ahead and publish all of my answers here um in the homework dot txt file for all the different questions. Um and today we're just going to do the same thing but I'm going to do it on the stream. So in this folder I'm going to create a homework X file there. Perfect. And I am going to copy over our first thing. So our first one is going to be to delete an element of a list. Perfect. So now I'm gonna go over to our elixir docks. Perfect. Go down to the function part here and delete act. This is a new list by removing the value at the specified index. So lead an element of a list. Um kate elite, which is a list of two poles. Yeah, we don't want to do that. Um Yeah, we're gonna do the, I think we'll do delete at Oh, it leads to give an element from a list. Perfect. That's what we want. So delete. So let's define our list. So let's say my Risk is equal to one two 34. Mm hmm. And then we'll do io dot but and we're going to do list dot delete and we're going to provide my list and we're going to say we're gonna want to delete three now if we drop the criminal ah I find this term it always takes so long to open intro less than five. And we're going to do elixir homework. Yes. Oh you know why it's because it's doing it. But we need to we'll see new risk is equal to and it will put out a new list. Inherently returning anything. Return for a new list without the element. So should okay we're having some sort of issue here. Do do do do do you need to inspect? Oh yeah because this isn't gonna be able to do a list. That's why. So maybe we can do it the previous way. But we're gonna need to use inspect instead of put because puts will only do strings or things that can come into strings like pure numbers. Perfect. So 124 awesome. Let's go and do there is an element at a given index within a list. So go over to homework here. Place at we're getting the list the integer and whatever we're wanting to replace it with. So let's say then for my list we're going to want to do io dot perfect rest dot place at And let's say we're going to want to replace Number 5 # four with eight. Um So we'll do my wrist. That will be the 3rd index. And we're gonna wanna replace it with eight. Perfect. So 1238. So that one's easy enough there. And then for this turn a list that contains lists as elements into a single list with no nested lists. Okay. So let's create are nested list to start with. We're gonna make a list and it's going to have a list of 12 And it's gonna have a list of three for it's gonna have a list of let's just say 56. So it has three lists of lists. So in javascript it's flattened. So I'm thinking it's probably going to be the same there. Yeah. So we should just be able to do flatten and then we'll be able to do That's good, first. Right? I. O. Dot inspect list dot flatten. Apologize if you can hear my dog barking in the background. Right? Um And 123456. Perfect. And the final question in our homework here was to any of the following functions, modify the original list. And no none of the following functions will modify the original list. Nothing is actually changing anything. And to prove this. Um at the end here we can do io dot inspect my list I O dot inspect mastered list. You can see we still have that 1234 of that original. And the Nesta went there. So they do not mutate because nothing is inherently going to mutate it. Um, at least nothing here is going to inherently mutated in elixir. So that is the homework for today. Um The docks are super clear for this, so it makes a lot of sense. Also, a lot of the naming is very similar to things in javascript. They're pretty intuitive to what the name is gonna be, so pretty straightforward.