👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
There are many beginner code challenges that will help you start to think more like an engineer. One such challenge is where you capitalize the first letter of every word in a given string. In this article, we’ll take a look at the prompt and several possible solutions in JavaScript.
Given a function, capitalize, which includes str as a parameter, return that str with each word capitalized. Try to think of peak cases in your solution (not as input, wrong type of input, etc.).
Approach
- Take a look again at the prompt. Write down or highlight any keywords you can find in the wording.
- Combine the meaning of the word problem. Part of the hardest part of doing code challenges is trying to figure out what the problem is asking you to do. Understanding the problem will help you go a long way in solving it.
- a possible pseudocode solution. It doesn’t have to be the actual code (it doesn’t need to be executable in your IDE or console browser - simple English is fine):
Solve the problem carefully step by step. It will help you think of tip cases - cases where an incorrect entry or an empty string may be passed - and how to break the problem down into logical steps. This is basically your experimentation phase - there are no wrong answers, just thoughts of how to approach the problem. These thoughts can be misleading or misguided - this is how you learn about won approaches to solving a problem