Preston Parry
Data Scientist, Machine Learning Engineer, addicted cyclist and rock climber
That's it.
That's it.
Sorry to disappoint- no nuclear physics here, folks.
All these are just a set of instructions to accomplish a specific task.
Reverse a string.
Define the problem:
1. Take in a string
2. Return a string
3. Returned string must be the reversed order of the original string
Reverse a string.
Constraints:
1. Are we allowed to use native JS functions?
2. Are we allowed to change it from a string into an array?
Reverse a string.
Exploring Patterns/Techniques:
1. Does JS have a native method that does this?
2. Can we try swapping items?
3. Could we just iterate through the string backwards?
4. What if we turned the string into an array of characters?
Reverse a string.
Simple plan:
1. Get input into a form we can iterate through backwards
2. iterate through it backwards
3. add each character to reversedString variable
4. return reversedString
Reverse a string.
Pseudocode
1. split the string into an array
2. iterate through that array backwards
3. push each item into a reversedArray
4. join reversedArray
5. return reversedArray
What does this mean for you?
Make the most basic possible version first.
Don't worry about edge cases.
Don't worry about handling everything.
Just get something out the door that is one step closer to what you're trying to accomplish.
If you're asked to put two dozen things on a board at specific positions:
Start by putting a single thing on the board.
Then put two dozen things anywhere on the board.
Then worry about how to position them all.
This makes your job much easier.
You don't need to solve the whole thing at once, just one tiny next portion of it.
Celebrate each step along the way.
Each one gets you a little bit closer to what you're trying to accomplish.
MVP lets you write code that isn't great. It's not your goal to write amazing code the first time through it!
In fact, if you write amazing code on your first try, you're probably doing it wrong and spending way too much time on that first attempt.
Leave yourself notes when you're writing crappy code. //TODO: this is inefficient. We can stop checking values if XYZ condition is false.
Once you've got a super basic version up and working, make rapid changes to improve it from there.
These exercises are a review from last week and are not necessarily tied to today's lecture material
https://github.com/TelegraphPrep/week2
By Preston Parry
Data Scientist, Machine Learning Engineer, addicted cyclist and rock climber