Skip to content

Instantly share code, notes, and snippets.

View fortunee's full-sized avatar
🎯
Focusing

Fortune Ekeruo fortunee

🎯
Focusing
View GitHub Profile
@fortunee
fortunee / function.hoisting.js
Created November 7, 2017 23:39
Function Hoisting
console.log(func1);
console.log(func2);
let func1 = function() {
// do something
}
function func2() {
// do another thing
}
@fortunee
fortunee / searchAlgorithms.js
Last active February 18, 2019 22:45
searchAlgorithms
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
@fortunee
fortunee / insertionSort.js
Last active March 9, 2023 04:17
Insertion Sort: sorting algorithm
/**
* 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
@fortunee
fortunee / selectionSort.js
Created February 19, 2019 10:44
Selection sort algorithm
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;
}
@fortunee
fortunee / breadthFirstSearch.js
Last active May 9, 2019 21:21
Breadth First Search JavaScript implementation
class Node {
constructor(data) {
this.data = data;
this.children = [];
}
}
class Graph {
constructor(root) {
this.root = root;
@fortunee
fortunee / ruleOne.js
Last active June 9, 2019 18:34
The first rule of javascript this keyword example
// 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()
@fortunee
fortunee / ruleTwo.js
Created June 9, 2019 18:35
The second rule of javascript this keyword example
// 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();
@fortunee
fortunee / ruleThree.js
Created June 9, 2019 18:39
The third rule of javascript this keyword example
// 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;
@fortunee
fortunee / ruleFour.js
Created June 9, 2019 18:41
The fourth rule of javascript this keyword example
// Rule #4 example
this.value = 'Some value';
function ruleFour() {
console.log('Rule four value >>>>', this.value);
}
// Refers to the global "this" value
ruleFour();
@fortunee
fortunee / ruleFive.js
Created June 9, 2019 18:44
The fifth rule of javascript this keyword
// 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();