Another Codewars puzzle in Rust!

Transcript

English (Auto-generated)

has. And today we're going to do another code wars problem. Uh recently we did one that was really simple and this time we're gonna try something a little more interesting and complicated and see how it goes. So let's hop on code wars and see the problem. It's reverse words, complete the function that accepts a string parameter and reverses each word in the strength and spaces should be retained. So there's a bunch of spaces will still want that many spaces but individual words should be swapped around. So this becomes seat is becomes C and becomes na and example becomes alright. There you go. So pretty simple. Looks like something we would have to do is Well, let's open up our editor and I'll edit the code here so that you can see it in your uh little podcast editor. Mm hmm I want to say that we are going to what are we gonna have to do? Well, so I'm gonna get out of here cause I always get up co pilot is just going to try to solve it for me. So, so what we wanna do is first split the string. We'll split it by spaces. Mm Okay. And then that will give us each word right at this point, man. You know, I think I could just turn a yeah, I should deactivate copilot because otherwise it's just gonna give us the answer. Okay, So we're gonna map it. We're gonna map it to each word. Mm hmm. Also I want to say is hey, when you want to reverse that word, we're gonna use rev but since we have a string first we have to turn it into chars I believe that gives us a vector of characters. I forget the exact type. In any case you can't just reverse a string, you have to get it some other data type and the way you do that is with chars then we reverse it. Okay that will give us a map of don't give us a map of what would you call it of all these words but we want them to be back into a string right? This is a string with each word reverse. So what we'll do is we'll collect this. I'm going to collect it into a vector, any type and so we don't care what's in the vector. In fact I think we know what's in the victory is um okay streams right to teach work but we're not gonna worry about it. So we have that collected into a vector and then we're gonna want to join it back in using space characters. I think something like that should work. Let's see I believe I'm missing something. Alright when we reverse the characters, we also have to collect those. Mhm And maybe we can add a little bit of structure here. Yeah, so we have this function we create here and what I'm saying is that yeah we get the charge, we reverse them and collected and what we're going to collect that into is back into a string. So we'll just say that hey, by the way, and to collect it into is a string. Alright, let's just look at that real quick, yep, looks good to me, let's try it down and it actually works. I'm so used to rust just having all these compilation errors whenever I run anything, but I guess we're getting more competent. Alright, so we can submit that and get some points. It's all about the points. We'll say we are very satisfied with this problem because it was fun. I wonder if I ever solved this in another language, You know, just rest. Okay. There you go. I hope that was educational for you. I hope you enjoyed that. We will have more rust content coming soon. I'm gonna be focusing on using interesting learning resources, things you may not know about. I mean everyone knows about the rest book, but there's a lot of other fun ways to learn things you can try out projects you can do that, you may never have heard of. So I'll keep trying to introduce those to you, show you new stuff and have fun along the way. Thanks again for your time and I'll see you next time. Bye bye.
77 Views 1 Likes 0 Comments

Let's try something more advanced this time

Comment
Leave a comment (supports markdown format)