Skip to content

Instantly share code, notes, and snippets.

View hlpetway's full-sized avatar
😸

Hailey Petway hlpetway

😸
View GitHub Profile
@hlpetway
hlpetway / xor.js
Created April 10, 2014 18:33 — forked from hankyates/xor.js
// Implement an exclusive OR function called `preferredName` that has the following interface:
var FirstName,
LastName;
preferredName(FirstName, LastName);
// -> false
FirstName = 'Hank';
// Given the following data structure
// implement a oldestLivingFather method
// that will return the name of the oldest
// living father.
var people = [
{
name: 'Hank',
age: 29,
father: 'Don'
@hlpetway
hlpetway / gist:f2a8e402dbc6cd60170a
Last active August 29, 2015 14:20
Rotate Array Recursive Solution - Otto's Version
//-------------------------------------------------------------------
// ** Recursive Solution **
var numbers = [1,2,3,4,5,6,7];
var recursiveRotateArray = function (numberSet,k,n) {
counter = k;
sizeOfArray = n;
if(counter > 0){
@hlpetway
hlpetway / gist:cea6e7811b5d26c95ef8
Last active August 29, 2015 14:21
Product Of All Other Numbers
//Using a Memoize-like approach
//Loop through multiplying intergers before each index for each position in the array.
//Then loop through backwards multiplying intergers after each index for each position. TADA!
var get_product_of_all_ints_except_index = function(arrayOfInt){
productsOfAllIntegers = [1,1,1,1,1];
//There is no way in JS to instantiate an array
//of a specific size and with specific values other than looping through.
//This is to help solve the zero or an array of size 1 edge cases.
var product = 1;