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âŚ
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.
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?
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.
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.
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.
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.