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
//#######PLUCK####### | |
var myPluck = function(obj, propName) { | |
var arr = []; | |
for (var i = 0; i < obj.length; i++) { | |
for (var prop in obj[i]) { | |
if (prop === propName) | |
arr.push(obj[i][prop]); | |
} | |
} |
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
arr = [7, 7, 9, 2, 45, 6, 34, 43, 2, 6, 8, 2, 4, 100, 100, 100, 23, 34, 4]; | |
var uniq = function(arr) { | |
return arr.filter(function(value, index, self) { | |
// only returns uniq numbers. A duplicate will yield a different indexOf | |
return self.indexOf(value) === index; | |
}).sort(function(x, y) { | |
return x - y; | |
}); | |
}; |
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
var shuffle = function(arr) { | |
var rand, temp; | |
//loop through array and swap out value at random position | |
//with value at iteration position of array | |
for (var i = 0; i < arr.length; i++) { | |
//generate random number between 0 and length of array. | |
rand = Math.floor(Math.random() * arr.length); | |
temp = arr[i]; //store value of arr[i] to swap later | |
arr[i] = arr[rand]; //set arr[i] to random position value | |
arr[rand] = temp; //replace with temp |
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
var cipher = function(str, num) { | |
var code = 0, | |
cipher = ''; | |
for (var i = 0; i < str.length; i++) { | |
code = str.charCodeAt(i); | |
//check lowercase | |
if (code >= 97 && code <= 122) { | |
code += num; |
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
/* RECURSION ( when a function invokes itself to solve a problem ) | |
All recursive functions have the following characteristics: | |
1) The method is implemented using if-else logic that leads to | |
different cases. | |
2) One or more base/terminating cases(the simplest case) are | |
used to stop the recursion ex. if (n === 0) stop | |
3) Every recursive call reduces the original problem, bringing | |
it increasingly closer to the terminating base case until |
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
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 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 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 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: alexhawkins.me@gmail.com | |
* GitHub: github.com/alexhawkins | |
* LinkedIn: linkedin.com/in/alexhawkinsme/ | |
****************************************************************************/ | |
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
//1) reverse a string without using any variables or | |
/*****************************************************/ | |
function reverseString(s) { | |
if (s === '') | |
return ''; | |
else | |
return s.slice(1) + s[0]; | |
} |