Skip to content

Instantly share code, notes, and snippets.

View thomasvaeth's full-sized avatar
🍕

Thomas Vaeth thomasvaeth

🍕
View GitHub Profile
@thomasvaeth
thomasvaeth / cassidoo Challenge 10-27
Last active October 28, 2019 17:04
"The successful warrior is the average man, with laser-like focus." - Bruce Lee
function missingInts(arr) {
if (arr.length < 2) return [];
const missingNums = [];
const set = new Set(arr);
for (let i = 1; i < arr[arr.length - 1]; i++) {
if (!set.has(i)) missingNums.push(i);
}
& when not (@side = null) {
& when not (@side = x) {
& when not (side = y) {
.size(~"@{property}-@{side}", @property, @size);
}
}
}
@thomasvaeth
thomasvaeth / cassidoo Challenge 8-7
Created August 8, 2019 05:46
"If you knew how much work went into it, you would not call it genius." - Michelangelo
function validTriangle(a, b, c) {
if (a + b <= c || a + c <= b || b + c <= a) return false;
return true;
}
validTriangle(60, 80, 40);
validTriangle(5, 5, 50);
function Node(data) {
this.data = data;
this.left = null;
this.right = null;
}
function BST() {
this.root = null;
}
@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) {
@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 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 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 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 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];
}
}