This file contains hidden or 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 hidden or 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 hidden or 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(age); // -> undefined | |
| var age = 22; | |
| console.log(age); // -> 22 | |
| console.log(location); // throws -> Uncaught ReferenceError: location is not defined | |
| location = 'Lagos, Nigeria'; | |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| let name = 'Fortune'; | |
| function func() { | |
| let age = 22; | |
| console.log(name, age); | |
| } | |
| func() // 'Fortune 22' | |
| // Accessing age here throws |
This file contains hidden or 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
| 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' |
This file contains hidden or 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
| // 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) |
This file contains hidden or 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
| // 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) |
This file contains hidden or 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
| // 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) |
This file contains hidden or 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
| node_modules/ | |
| .env |