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
People seem to believe that they are either naturally good or bad at algorithms
-Really its just a skill you can develop
-And like any other skill you need a bag of tools/tricks
-Lets talk about some of these tools and tricks
1: Don't get bogged down in code!
2: Work with a friend
3: Get out your whiteboard and draw a picture
4: Don't be afraid of trying something out that doesn't work
5: Walk through a simple baby example
6: Change the algorithm to something easier to solve or something you know how to solve
-Its really easy to get lost in the trees and lose sight of the forest
-Going straight to JavaScript and trying to make everything work perfectly is not going to end well
-Making all the indices correct is frustrating
-Stay at a very high level with psuedocode
-Find a friend (or rubber duck) to bounce ideas off
-This will force you to verbalize what you are trying to do
-Often times you will realize the problem and come to a solution just by trying to describe it
-The vast majority of major algorithms are done via collaboration
-Don't be an island!
-Turns out thinking abstractly doesn't come naturally to humans (nor does statistics and big numbers)
-But we can take in an incredible amount of information via visuals
A Beautiful Tree!
-My favorite way to write algorithms is just trying anything I can think of and seeing what happens
-Worst Case Scenario: it didn't work and we just learnt more about the problem
-Best Case Scenario: it totally works
-Middle Case Scenario: it kind of worked but need to modify it
-Do step by step through the simplest case you can think of
-Pretend you are the computer and REALLY go through it
-There are no rules saying you have to solve the exact algorithm straight away
-Think of what this particular algorithm reminds you of and solve that!
-Example: You have an array and I ask you to return me the 7th largest item in the array
-Thought Process: Well if the array is already sorted I just give you array[array.length-7-1]...