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
rotateAndCache = function(image,angle) { | |
var offscreenCanvas = document.createElement('canvas'); | |
var offscreenCtx = offscreenCanvas.getContext('2d'); | |
var size = Math.max(image.width, image.height); | |
offscreenCanvas.width = size; | |
offscreenCanvas.height = size; | |
offscreenCtx.translate(size/2, size/2); | |
offscreenCtx.rotate(angle + Math.PI/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
const assert = function (condition, message) { | |
try { | |
console.assert.apply(console, arguments); | |
if (typeof message === 'string' && condition) { | |
console.log('✔ ' + message); | |
} | |
} catch(error) { | |
assert.exitCode = 1; | |
console.error('✖ ' + error); | |
} |
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 LFUCache = function(capacity) { | |
this.cache = {}; | |
this.capacity = capacity; | |
this.population = 0; | |
}; | |
LFUCache.prototype.get = function(key) { | |
if(this.LRUkey && key === this.LFUkey) { | |
this.cache[key].use += 1; | |
//check if any others have an equal amount of uses |
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
const productExceptSelf = (nums) => nums.map((num,i) => nums.reduce((acc,number,j) => (i!==j ? acc *= number : acc), 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 TreeNode(val) { | |
this.val = val; | |
this.left = this.right = null; | |
} | |
const kthSmallest = function(root, k, smallestArray=[]) { | |
if(smallestArray.length < k) { | |
smallestArray.push(root.val); | |
smallestArray.sort((a, b) => a - b); | |
} else if(smallestArray.find(value => value > root.val)) { |
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 fetchSomeResources() { | |
return dispatch => { | |
// Async action is starting... | |
dispatch({type: FETCH_RESOURCES}); | |
someHttpClient.get('/resources') | |
// Async action succeeded... | |
.then(res => { | |
dispatch({type: FETCH_RESOURCES_SUCCESS, data: res.body}); |
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
const hasPathToSum = function(node, targetSum) { | |
let targetSumCopy = targetSum - node.value; | |
if(targetSumCopy === 0 && node.children.length === 0) { | |
return true; | |
} else if(targetSumCopy < 0 || node.children.length === 0 ){ | |
return false; | |
} else { | |
//target sum > 0 and there are children | |
var find = node.children.find(child => hasPathToSum(child, targetSumCopy)); | |
if(find) { |
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 cashAmount = function(amount) { | |
this.amount = amount * 100; | |
this.reduceBy = function(amountToModulo) { | |
var divideCount = 0; | |
console.log('amount: ', this.amount); | |
while(this.amount >= amountToModulo) { | |
this.amount -= amountToModulo; | |
divideCount++; | |
} | |
return divideCount; |
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 colors = { | |
ALICEBLUE: '#F0F8FF', | |
ANTIQUEWHITE: '#FAEBD7', | |
AQUA: '#00FFFF', | |
AQUAMARINE: '#7FFFD4', | |
AZURE: '#F0FFFF', | |
BEIGE: '#F5F5DC', | |
BISQUE: '#FFE4C4', | |
BLACK: '#000000', | |
BLANCHEDALMOND: '#FFEBCD', |
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 Board = function(n) { | |
this.board = []; | |
for(var i = 0; i < n; i++) { | |
var row = []; | |
for(var j = 0; j < n; j++) { | |
row.push(0); | |
} | |
this.board.push(row); | |
} | |
}; |