- Stop! turn off the negative thinking
- Take a deep breath
- Find a micro goal
- Positive Mental Attitude - (silly mantra is helpful)
- Rinse and repeat!!!!!
| /*********DISCLAIMER***********/ | |
| /* there is more than one way to do a sort :) */ | |
| function swap(arr, idx1, idx2) { | |
| var temp = arr[idx1]; | |
| arr[idx1] = arr[idx2]; | |
| arr[idx2] = temp; | |
| } |
| // 1. declare a new empty array, and pointers | |
| // corresponding to indices in arr1 and arr2 | |
| // (set them both to 0) | |
| // 2. if the first element in arr1 is less than the | |
| // first element in arr2, push the first element in | |
| // arr1 to the new array, and move the pointer for | |
| // arr1 one spot to the right. Otherwise, do this for arr2. | |
| // 3. Repeat this process until you've gone through |
| // perform a search bigO(n^2) | |
| function bubbleSort(arr) { | |
| // loop through every array element: indices: 0 thru (last-1) | |
| // note starting i at 1 - we need to be able to decrease the looping iterations and if | |
| // we had used a zero index, the loop would not progress correctly | |
| // this is because each iteration moves the highest value in the lopped through set | |
| // to the last element. So on the next iteration, we can skip examining the last element |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> |