What exactly is the PREP Method?
PREP is a mnemonic way to problem solve your coding issues/challenges. This type of thinking can help you break down the problem logically.
Let's break down what PREP stands for...
- P - Parameters
- R - Return
- E - Examples
- P - Psuedocode
P - Parameters
Let's first figure out what parameters are in this problem. In this example, there are 2 parameters mentioned:
s. The "types" of parameters we need is a "number" and a "string", hence why they named it
Look at that! We just finished the first step of PREP! 🥳
R - Return
The second step is to figure out what the function will return. In problem, it is asking for a "string"(
s) that is repeated by
n number of times.
E - Examples
Next, let's think of examples that could be returned. In this problem, they have given us a few examples.
What other examples can we think of? 👀
P - Pseudocode
Finally, it's time for some pseudocode. It's really up to you how you want to write your pseudocode, but essentially this is where you write what your code will do.
Another example below also works as pseudocode:
Now, we're ready to code!
This is where we can apply
repeat() to our code. Here is the syntax of this particular string method:
Let's apply what we just learned and see if it works!
Woohoo! It works! 🙌🏼 What are other potential ways we could solve this problem? 🤔
This kind of approach has helped me in so many codewars challenges and in my own projects! Once you get the hang of this tactic, challenges aren't as intimidating and big problems are then broken down into smaller chunks. Hope this brief explanation helps you out in your coding journey!
What are other ways you tackle your coding problems?
Thanks for reading my friend!
Follow me on Twitter and join my Timeout Tuesdays: twitter.com/izaye_visuals