Skip to content

Instantly share code, notes, and snippets.

View kylebakerio's full-sized avatar
⛰️
mountains are really nice, guys.

Kyle Baker kylebakerio

⛰️
mountains are really nice, guys.
View GitHub Profile
@kylebakerio
kylebakerio / gist:e5f49adfc8aed57f1e76
Last active August 29, 2015 14:13
Maker Square Algorithms Challenge
/*Instructions:
Submit a solution to the following challenge:
Given an array of integers, find the smallest difference between any two elements of the array. For example:
var findSmallestDifference = function(arr) {
// Your code goes here
};
var result = findSmallestDifference([100, 500, 300, 1000, -200, 990]);
@kylebakerio
kylebakerio / algorithimschallenge.js
Last active August 29, 2015 14:14
return the smallest positive difference between elements of an array of numbers
var findSmallestDifference = function(arr) {
var differences = [];
arr.sort(function(c,d){return c - d});
for(a=0;a<arr.length;a++){
for(b=a+1;b<arr.length;b++){
differences[differences.length] = arr[b] - arr[a];
}
}
var answer = (differences[0]*2)
for (e=0;e<differences.length;e++){
var decryptC = function(message) {
console.log("Becky's Code")
var wordString = "", whatWord = "", results = "", result = "", messageArray = message.split(" "), arrayLength = messageArray.length;
for (var i = 0; i < arrayLength; i++) { //for each word (i) do the following
if(messageArray[i].length > [i]) { //if this word is longer than how many letters we need
result = messageArray[i].charAt(i); //add that letter of the word to result
results += result; //add result to the result string
}
else {
wordString = "";
function lessOfTwo(a,b){
a < b ? a : b;
};
console.log(lessOfTwo(10,20));
function countChars(string, char){
b = 0;
for (i=0;i<string.length;i++){
if (string.charAt(i) === char) b++
}
return b
};
countChars("BBbbbcccdsdhshBBzb", "b")
function isEven(number) {
if (number === 0) return true;
else if (number === 1) return false;
else {
if (number < 0) return isEven(number + 2);
else if (number > 35663) return "number too big";
else return isEven(number - 2);
}
};
var memoize3 = function(func) {
var memoized = function(key) {
if (!memoized.cache.hasOwnProperty(key)) memoized.cache[key] = func.apply(this, arguments);
return memoized.cache[key]
}
memoized.cache = {};
return memoized;
function stringifyJSON(subject) {
var output = '';
var type = typeof subject;
if (type === 'number') {
return subject.toString();
} else if (subject === null) {
return 'null';
} else if (type === "boolean") {
return subject.toString();
} else if (type === "string") {
function param7(param) {
return param + 7;
}
1 === 2 ?
console.log("statement 1 passes") :
1 === 3 ?
console.log("statement 2 passes") :
1 === 1 ?
function(){
var getElementsByClassName = function(className){
var output = [];
var childAdd = function(aNode) {
if (_.contains(aNode.classList, className)) {
output.push(aNode)
}
if (aNode.childElementCount > 0) {
_.each(aNode.childNodes, function(val){
childAdd(val)
})