Javascript Coding Challenges for Beginners Q14

Transcript

English (Auto-generated)

Hello everyone welcome back to my Javascript coding challenge for beginners. Today we're working on question 14 and we will stop using java will stop learning about Javascript built in functions because we have went through plenty of them and I'm sure by now you guys have mastered some of it. So from now on will be still using those functions but we won't be explaining everything in detail anymore. So today we want to create a function that can count every letter in a string. So for example if we have kata it should return as C one, A two and T one. So when you guys are ready, pause the video and come up with their own solutions and when you're ready we can solve the problem together. So now that you're ready, let's tackle the solution together. So today the string that I chose is the video just because the video is reporting their earning. Not so great but that's fine. Still on the video, graphics card lover uh going to a solution so because we want to return it in the object for um we definitely want a holder. So I guess I'll let object for a empty object to hold our result and next because we have uppercase um we want to return them all back in lower case. I'm gonna assign my string into a new variable. So I guess what are equal, Bring that to the authorities and then I also want to split it because I want it into I want my string in that reform. So not split And then now I want to look through my raid to get every single letter so that I can count them. So our dot for each you don't remember what each does do. Go back to my other videos and check out for each. Um I'm just gonna call it item because that's what I like to call it. So for each item if object item is equal to undefined, I want to set a new object item into one so that's gonna be my first count. And else if object item does already exist as my own statement, I just want to increase the accounts of plus plus and then now I want to return. So what this is saying is if a object bracket item which means this is the key and the key is undefined. That means it does not exist in our object just yet. So if it doesn't exist I want to assign a value to it. So this is a typical key value pair assignments. So which means this key will have the value of one because it hasn't existed until now. But otherwise I just want to increment it by one because the object or the key already exists. So let's try to run this in the terminal and see if we get the answer that we want. So note 14 large. Js. So as you can see from the video we have N one B. One I. Two because we have two eyes. D. One and a. One. So if your if your answer is something different that is fine as well. But this is just the way I like to do it and I think it's very clean to read. So thank you all for watching. And when you're ready we can move on to the next solution.
89 Views 0 Likes 0 Comments

Count all the letters

Comment
Leave a comment (supports markdown format)