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
| //1) reverse a string without using any variables or | |
| /*****************************************************/ | |
| function reverseString(s) { | |
| if (s === '') | |
| return ''; | |
| else | |
| return s.slice(1) + s[0]; | |
| } |
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
| 'use strict'; | |
| /** APPLICANT INFO *********************************************************** | |
| ------------------------------------------------------------------------------ | |
| * Name: Alex Hawkins | |
| * Email: [email protected] | |
| * GitHub: github.com/alexhawkins | |
| * LinkedIn: linkedin.com/in/alexhawkinsme/ | |
| ****************************************************************************/ | |
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 HashTable = function() { | |
| this._storage = []; | |
| this._count = 0; | |
| this._limit = 8; | |
| } | |
| HashTable.prototype.insert = function(key, value) { | |
| //create an index for our storage location by passing it through our hashing function | |
| var index = this.hashFunc(key, this._limit); |
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
| /******************************************************/ | |
| /******************************************************/ | |
| /** | |
| * FUNCTIONAL QUEUE | |
| */ | |
| /** Queues are FIFO, first in first out */ | |
| 'use strict'; | |
| var makeQueue = function() { |
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
| /*MODULE PATTERN*/ | |
| //create a namespace | |
| var shoppingCart = (function() { | |
| //private variables | |
| var total; | |
| var basket = []; | |
| //private methods |
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
| /*HASH TABLE - a dictionary/hash map data structure for storing key/value pairs. Finding | |
| an entry in a hash table takes O(1) constant time(same for 10 as 1 billion items). Whereas | |
| finding an item via binary search takes time proportional to the logarithm of | |
| the item in the list O(logn). Finding an item in a regular old list takes time proportional to | |
| the length of the list O(n). Very slow. Hash Tables = very fast */ | |
| var makeHashTable = function(max) { | |
| var storage = [], | |
| hashTableMethods = { |
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
| /**********FUNCTIONAL - SHARED STACK IMPLEMENTATION ****************/ | |
| var makeStack = function() { | |
| var stack = { | |
| storage: {}, | |
| length: 0 | |
| }; | |
| extend(stack, stackMethods); | |
| return stack; |
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
| /* BASIC BUBBLE SORT ALGORITHM | |
| 1. Compare first item to the second item | |
| 2. Swap if first item should be after second | |
| 3. Compare second to third item | |
| 4. If second should be after third, swap | |
| 5. Continue until end of data set; | |
| */ | |
| //FAST BUBBLE SORT |
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 stringifyJSON = function(obj) { | |
| var objElements = []; | |
| //check for literals | |
| if (!(obj instanceof Object)) | |
| return typeof obj === 'string' ? '"' + obj + '"' : '' + obj; | |
| //check for arrays | |
| else if (Array.isArray(obj)) { | |
| return '[' + obj.map(function(el) { return stringifyJSON(el); }) + ']'; | |
| //check for object if not array | |
| } else if (obj instanceof Object) { |
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
| /* | |
| #DATA STRUCTURES & ALGORITHMS | |
| A) Binary Search with RANGE and Shuffle algorithms: | |
| -Algorithmic Steps | |
| 1) If needle == value in haystack, we're done. Exit. | |
| 2) If needle < middle value in haystack, go left. Go to step 1. |