This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log(func1); | |
console.log(func2); | |
let func1 = function() { | |
// do something | |
} | |
function func2() { | |
// do another thing | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const binarySearch = (array, value) => { | |
/** | |
* 1. Define a midPoint variable | |
* 2. Define and initialize min and max index variables | |
* 3. Perform a loop through the array | |
* 4. Assign the mid index of the array to the midPoint variable | |
* 5. Compare the current midPoint value with search value | |
* 6. Return value if midPoint value === search value | |
* 7. Reassign the min index if the midPoint val < search val | |
* 8. Reassign the max index if the midPoint val > search val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Insertion sort: | |
* Big O notation of O(n^2) due to the double loop | |
*/ | |
const insertionSort = (items) => { | |
/** | |
* 1. Loop through array of unsorted items | |
* 2. Grab the value of the current iteration index | |
* 3. Initialize j index for a second loop back through the sorted section | |
* 4. Loop back and compare the last item in the sorted section with the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const selectionSort = function(array) { | |
let temp; | |
for(let i = 0; i < array.length; i++) { | |
let minIndexVal = i; | |
for(let j = i + 1; j<array.length; j++) { | |
if(array[j] < array[minIndexVal]) { | |
minIndexVal = j; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
constructor(data) { | |
this.data = data; | |
this.children = []; | |
} | |
} | |
class Graph { | |
constructor(root) { | |
this.root = root; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Rule #1 example | |
function RuleOne() { | |
this.value = 'Some value for rule #1'; | |
this.printValue = function() { | |
console.log('Rule one value >>>>', this.value); | |
} | |
} | |
// using the new keyword here creates a brand new object for "this" | |
const ruleOneInstance = new RuleOne() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Rule #2 example | |
function RuleTwo() { | |
this.value = 'Some value for rule #2'; | |
this.printValue = function() { | |
console.log('Rule two value >>>>', this.value); | |
} | |
} | |
const ruleTwoInstance = new RuleTwo(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Rule #3 example | |
function RuleThree() { | |
this.value = 'Some value for rule #3'; | |
this.printValue = function() { | |
console.log('Rule three value >>>>', this.value); | |
} | |
} | |
const ruleThreeInstance = new RuleThree(); | |
const ruleThreePrintValue = ruleThreeInstance.printValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Rule #4 example | |
this.value = 'Some value'; | |
function ruleFour() { | |
console.log('Rule four value >>>>', this.value); | |
} | |
// Refers to the global "this" value | |
ruleFour(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Rule #5 example | |
function RuleFive() { | |
this.value = 'Some value for rule #5'; | |
this.printValue = function() { | |
console.log('Rule five value >>>>', this.value); | |
} | |
} | |
const ruleFiveInstance = new RuleFive(); |