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 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, |
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 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); |
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
// First Solution | |
function duplicate(arr, num) { | |
var newArr = []; | |
for (var i = 1; i <= num; i++) { | |
newArr = newArr.concat(arr); | |
} | |
return newArr; | |
} |
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 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) { |
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]; | |
} | |
} | |
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 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 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 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 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) { |
OlderNewer