Learn With Me | Intro To Elixir Lesson Seven - Recursion Homework

Elixir Web Development
Transcript

English (Auto-generated)

So I just finished less than seven in the intro to elixir series which is about record version and using pattern matching for recreation and um there's just a couple of different tasks for homework is going to go ahead and give those an attempt now. Um excursion is very much the thing I always struggled throughout my head around. Um so I'm gonna do my best but this might not be a very stand up example of learning elixir today. So I'm gonna go ahead and start with defining. I'm gonna find a module, I'll call it recursive Lod. Um Then let's go ahead and copy over what our first one is going to be have been killed and perfect. So we're gonna find the number of elements in a list. So just looking at this again, the notes Can be written as one plus this. Okay. So it's okay. Um so then what we'll do here, let's say um graph number of elements and we'll give it um list an empty list. They do, it's gonna return zero again as our control. Um and then we're gonna do another one. Um number um elements. This is gonna take in a list which is going to have our first element and then remember and we will do a review and an end. And then what we want to do is we want to return the count instead of the actual elements. So we'll do each one will be one. So we'll do one plus and then we'll call the number of elements and then they remain there. Mm hmm, I think that's right. Percival dot number of elements and it will do 1, 2, 3, 4. Well do I. Oh God, inspect here. Mhm. Everyone is unused. Who's that? Oops. I made my thing really tiny. A little bit bigger for you guys to what am I doing? Mhm. Okay. For this again. four, Awesome. Okay, 75 6. This is 123456 and eight, awesome. Okay. So that one works. So now we will go on to the next one which is just copy this over, convert a list of string composed of all the elements. Yes, For example, it delicious. 35 pay 10. You should return a string. 35 A 10. Okay. So mm hmm. Um let's do f compact spring. We're going to take in the list and we're going to do that would be straight. We're gonna do it again. So con cat string. Taking an empty list. Okay. And then we're going to I'm not gonna do this. We're gonna do element. Me either. Yeah. You and okay. And then we want to put, okay, the element is the first thing um and a string and then we want to add to that Comcast during the remainder. Mhm. Get rid of this. We'll do recursive mod uh con cat string copies that's over. So the arguments were given to recursive, string. No function clause matching and recursive mod Comcast String 3 5 Pay 10. Oh, of course bad argument and arithmetic expression. Okay, let's not use plus then we'll use this. Mm hmm. Hey, look at that. 3 5. Hey, 10. Perfect. Okay. So then I wonder if we can just do it like this or if we need it to be a string and it's something we needed to maybe be a string but argument error. Yeah. I didn't change anything else. Yeah. I think it needs to be a string. Ok. And let's go and see our last one. Find the largest element in a list. Note. May include features we haven't learned together yet. Um, yeah, I'm gonna leave that one for now because recursive is just a little bit too difficult and I'd rather not break my brain so managed to do it and hopefully that is the correct way.
143 Views 0 Likes 0 Comments

I do the homework for using pattern matching for recursion!

Comment
Leave a comment (supports markdown format)