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 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); | |
} | |
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
& when not (@side = null) { | |
& when not (@side = x) { | |
& when not (side = y) { | |
.size(~"@{property}-@{side}", @property, @size); | |
} | |
} | |
} |
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 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); |
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 Node(data) { | |
this.data = data; | |
this.left = null; | |
this.right = null; | |
} | |
function BST() { | |
this.root = null; | |
} |
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 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) { |
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 sortWithStack(arr) { | |
var stack = [], | |
current = null; | |
while (arr.length) { | |
current = arr.pop(); | |
while (stack.length && stack[stack.length - 1] > current) { | |
arr.push(stack.pop()); | |
} |
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 isEvenOdd(num) { | |
return Math.floor(num / 2) * 2 === num ? 'even' : 'odd'; | |
} | |
isEvenOdd(2); | |
isEvenOdd(3); |
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 deleteNumbers(arr, num) { | |
return arr.filter(item => item <= num); | |
} | |
deleteNumbers([1, 11, 4, 33, 22, 36, 39, 6, 29, 34], 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 overlapArea(arr1, arr2) { | |
const rect1 = { | |
left: arr1[0], | |
right: arr1[2], | |
top: arr1[1], | |
bottom: arr1[3] | |
}; | |
const rect2 = { | |
left: arr2[0], |
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 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]; | |
} | |
} | |
NewerOlder