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
/*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]); |
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 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++){ |
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 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 = ""; |
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
function lessOfTwo(a,b){ | |
a < b ? a : b; | |
}; | |
console.log(lessOfTwo(10,20)); |
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
function countChars(string, char){ | |
b = 0; | |
for (i=0;i<string.length;i++){ | |
if (string.charAt(i) === char) b++ | |
} | |
return b | |
}; | |
countChars("BBbbbcccdsdhshBBzb", "b") |
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
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); | |
} | |
}; |
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 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; |
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
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") { |
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
function param7(param) { | |
return param + 7; | |
} | |
1 === 2 ? | |
console.log("statement 1 passes") : | |
1 === 3 ? | |
console.log("statement 2 passes") : | |
1 === 1 ? | |
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
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) | |
}) |
OlderNewer