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 / 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 / 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 / variable.hoisting.js
Last active November 13, 2017 21:51
Hoisting
console.log(age); // -> undefined
var age = 22;
console.log(age); // -> 22
console.log(location); // throws -> Uncaught ReferenceError: location is not defined
location = 'Lagos, Nigeria';
@fortunee
fortunee / block.statement.js
Last active November 10, 2017 11:09
Block statement
for(var i = 1; i <= 5; i++) {
console.log('Number: ' + i);
}
// Variable i is accessible here
console.log(i) // -> 6 - which is the last value of i incremented by 1
/**
* However, using the ES6 let or const keyword to declare the variable
* makes it behave like a scope as it's only accessible within the for
@fortunee
fortunee / local.scope.js
Last active November 6, 2018 15:00
Local (Function-level) Scope
let name = 'Fortune';
function func() {
let age = 22;
console.log(name, age);
}
func() // 'Fortune 22'
// Accessing age here throws
@fortunee
fortunee / global.scope.js
Last active November 13, 2017 21:26
Global Scope
var name = 'Fortune';
var age = 22;
function func() {
// Both name and age can be accessed here
console.log(`The name is ${name}, and I'm ${age} years old`);
}
func() // 'The name is Fortune, and I'm 22 years old'
@fortunee
fortunee / postTweet.js
Last active May 30, 2017 08:28
Posting tweets
// We import our installed libraries from line 1 to 3
const Tweet = require('twitter');
const dotenv = require('dotenv').config(); // Call the config function of dotenv
const readline = require('readline');
/**
* We create a new instance of Tweet which we required
* above passing in our secret information as an object
* and using process.env to fetch the actual value from
* where it was set in our environment variable (.env file)
@fortunee
fortunee / getTweets.js
Last active May 30, 2017 08:23
Getting user's tweets
// We import our installed libraries from line 1 to 3
const Tweet = require('twitter');
const dotenv = require('dotenv').config(); // Call the config function of dotenv
const readline = require('readline');
/**
* We create a new instance of Tweet which we required
* above passing in our secret information as an object
* and using process.env to fetch the actual value from
* where it was set in our environment variable (.env file)
@fortunee
fortunee / getTweets.js
Last active May 30, 2017 08:27
Setup Twitter Configuration and API Keys
// We import our installed libraries from line 1 to 3
const Tweet = require('twitter');
const dotenv = require('dotenv').config(); // Call the config function of dotenv
const readline = require('readline');
/**
* We create a new instance of Tweet which we required
* above passing in our secret information as an object
* and using process.env to fetch the actual value from
* where it was set in our environment variable (.env file)
@fortunee
fortunee / .gitignore
Created May 29, 2017 18:53
Prevent Git from pushing our .env file and the node_modules directory
node_modules/
.env