Skip to content

Instantly share code, notes, and snippets.

View thomasvaeth's full-sized avatar
🍕

Thomas Vaeth thomasvaeth

🍕
View GitHub Profile
@thomasvaeth
thomasvaeth / please-dont-go
Created January 14, 2017 22:22
Snippet for Title/Favicon Change
var PleaseDontGo = (function() {
var s;
return {
settings: {
originalTitle: document.title,
// New title when tab is changed
newTitle: 'Please Don\'t Go',
favicon: document.querySelectorAll('[rel="icon"]')[0],
originalFavicon: document.querySelectorAll('[rel="icon"]')[0].href,
@thomasvaeth
thomasvaeth / cassidoo Challenge 9-17
Last active February 12, 2018 21:50
"Opportunities lie in the place where the complaints are." - Jack Ma
function seatsInTheater(numCols, numRows, myCol, myRow) {
var calcCols = myCol > numCols / 2 ? numCols - myCol + 1 : myCol,
unblocked = ((numCols - calcCols) * numRows) + ((myRow - 1) * calcCols);
return numCols * numRows - unblocked - 1;
}
seatsInTheater(16, 11, 5, 3);
@thomasvaeth
thomasvaeth / cassidoo Challenge 9-24
Last active February 12, 2018 21:50
"If you have a strong purpose in life, you don't have to be pushed. Your passion will drive you there." - Roy T. Bennett
// First Solution
function duplicate(arr, num) {
var newArr = [];
for (var i = 1; i <= num; i++) {
newArr = newArr.concat(arr);
}
return newArr;
}
@thomasvaeth
thomasvaeth / cassidoo Challenge 2-11
Last active February 12, 2018 22:12
"Curiosity will conquer fear even more than bravery will." - James Stephens
function productArrayValues(arr1, arr2) {
return quickSort(arr1, 0, arr1.length - 1)[arr1.length - 1] * quickSort(arr2, 0, arr2.length - 1)[0];
}
function quickSort(arr, left, right) {
if (arr.length < 2) return arr;
var pivot, partitionIndex;
if (left < right) {
@thomasvaeth
thomasvaeth / cassidoo Challenge 2-18
Created February 19, 2018 18:32
"The further a society drifts from the truth, the more it will hate those that speak it." - George Orwell
function minimumDiff(arr) {
var sortedArr = mergeSort(arr),
difference = sortedArr[1] - sortedArr[0];
for (var i = 1; i < sortedArr.length; i++) {
if (sortedArr[i] - sortedArr[i - 1] < difference) {
difference = sortedArr[i] - sortedArr[i - 1];
}
}
@thomasvaeth
thomasvaeth / cassidoo Challenge 3-12
Created March 13, 2018 01:33
"Spiteful words can hurt your feelings but silence breaks your heart." - C.S. Lewis
function overlapArea(arr1, arr2) {
const rect1 = {
left: arr1[0],
right: arr1[2],
top: arr1[1],
bottom: arr1[3]
};
const rect2 = {
left: arr2[0],
@thomasvaeth
thomasvaeth / cassidoo Challenge 4-9
Last active April 11, 2018 17:29
"A diamond is a piece of coal that stuck to the job." - Michael Larsen
function deleteNumbers(arr, num) {
return arr.filter(item => item <= num);
}
deleteNumbers([1, 11, 4, 33, 22, 36, 39, 6, 29, 34], 20);
@thomasvaeth
thomasvaeth / cassidoo Challenge 4-23
Created April 23, 2018 16:54
Wherever you are, be there totally." - Eckhart Tolle
function isEvenOdd(num) {
return Math.floor(num / 2) * 2 === num ? 'even' : 'odd';
}
isEvenOdd(2);
isEvenOdd(3);
@thomasvaeth
thomasvaeth / cassidoo Challenge 5-1
Created May 7, 2018 18:28
"Opinion is the medium between knowledge and ignorance." - Plato
function sortWithStack(arr) {
var stack = [],
current = null;
while (arr.length) {
current = arr.pop();
while (stack.length && stack[stack.length - 1] > current) {
arr.push(stack.pop());
}
@thomasvaeth
thomasvaeth / cassidoo Challenge 6-12
Created June 12, 2018 21:41
"In the midst of chaos, there is also opportunity." - Sun Tzu
function closestProduct(arr, num) {
const result = [];
let total = 0;
let difference = Infinity;
for (let i = 0; i < arr.length; i++) {
for (let j = i + 1; j < arr.length; j++) {
total = arr[i] * arr[j];
if (Math.abs(total - num) < difference) {