Test questions obliterated me?!😂

Man, I really need help understanding these ‘leet code’ style questions.

Vowel Count
Have the function VowelCount( str ) take the str string parameter being passed and return the number of vowels the string contains ( ie. “All cows eat grass and moo” would return 8). Do not count y as a vowel for this challenge.

Swap Case
Have the function SwapCase( str )take the str parameter and swap the case of each character. For example: if str is “Hello World” the output should be hELLO wORLD . Let numbers and symbols stay the way they are.

I thought that I was understanding javascript, but I ran into these types of problems, and I really have no idea how to solve them on my own…I mean, if I see a solution to one, I can understand it and it makes sense. But as far as coming up with the solutions on my own, im completely stuck…

Im a little discouraged because I feel like I should be able to do these for as long as Ive been using Javascript… but I can’t.

like I said, I can totally understand the solutions. but Im having the hardest time solving them on my own…

Im feeling frustrated. I don’t think Ive spent any time working on this type of javascript (mainly because its very uninspired and uninteresting to me). Please help me understand these type of questions… :pray::mask:

Just to be clear, im not looking for solutions to these two examples. but more so advise on how to begin learning how to solve questions like the ones above; or advise on what steps I should take to get better to where u can solve this type of thing…

The advice is - take a piece of paper and try out doing the task at hand. Then try breaking down what you are doing into step-by-step steps (haha). Once you got those down, start thinking about code.

Like, how do you count vowels? Well you take your knowledge of what a vowel is, start by 0 and then go through a word one character after another and if the character is a vowel, you count one up.

Same with switching the case. You go character by character, check if it’s lowercase and if so, switch it to uppercase. Or the other way around.
Ofcourse for this you need to know how a computer identifies “case”. Which it usually doesn’t, it just knows ASCII and so you have to get the ASCII values of letters and work with that.

But yeah, the first thing most problems come down to is some kind of loop. Hence the step-by-step approach.
When you understand those, you can busy yourself with advanced data structures and functions and whatnot. All that however builds upon the idea of breaking down large problems into smaller problems. Because a computer is REALLY stupid, so you end up having to find a way to create a set of tasks even that stupid piece hardware can understand and execute.


I get that. That makes total sense. :pray: thank you.

Im little concerned about committing to memory methods like .toUpperCase and .split and the like… those are not really second nature to me… I guess I just need to get used to using those basic methods…

Ive mores spent my time understanding how functions work (ie accepting parameter) how functions work in the arrow function format, anonymous functions. How to use arrays in functions and function scope… How event listeners work etc.

-those types of ‘concepts’. but the hardcore methods and data structures have alluded my learning. Because its alot to think about just how the javascript works with the dom you know?

Does that make sense?

Sure sure, once you got the basics down, you enter a field where people built upon these basics and especially with a widespread language like JS, there is just tons upon ton of stuff. Heck just being a frontend developer for like a single JS-Framework can make up an entire career. And there are dozens of frameworks…

Although you don’t memorize a lot of functions. You get some resource to look them up and Google on Stackoverflow.

Things like functions, scope and such is a matter of practice however. At first it seems complicated because you are not used to it, but at some point it will become second nature.
Like, the first time I worked with hash-tables, my mind couldn’t get around what the freaking heck these are and how they are different from arrays. Nowadays I use them quite regularly.
Or linked-lists. Frankly I don’t use them for anything but I can easily wrap my head around how they work and what I might need to do, which took me a long time when I first encountering them on some Leetcode questions.

1 Like

You don’t need to memorize methods.
You just have to be aware that they exist.
If you forget syntax then look it up.
That is what MDN docs is for. :grinning:

I think part of the problem is that you are diving into the javascript code first before working out the problem like @Jagaya said.

Once you have a worked out the problem without code, then you can go through and slowly code it out.

Part of these coding challenges is learning how to research for different javascript methods.

You can google things like,
“How to create a regex for this?”
“How to do this with objects”
“How to do x”

The more problems you solve the better you will get at learning about the different methods.

It will also help when you are building out your individual projects.


Got it. so there is definitely and emphasis on working out the problem first before trying to code it out. That makes sense.

I was just concerned about this aspect because I agree with this. But although ive never been given an ‘official’ live coding challenge; Im not sure of their expectations.

does that make sense?

Makes sense. Thanks for clearing up a lot of my confusion. I really like how you broke things down here :pray:

The biggest thing is being able to talk through your process.
In an interview situation they want to be able to see your thought process and problem solving skills.

You can always let them know,
“I plan to solve it like this, but I just need to double check on the correct syntax for this method here”

Remember that they are checking for your problem solving skills. :grinning:


Very well put. Thanks so much for breaking that down. Thats something that I have been wondering about since I started learning. Im curious to know in depth what to expect in a real life coding interview situation.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.