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
// Link to codepen https://codepen.io/jaspercreel/pen/MvxpKZ?editors=0010 | |
const clock = function() { | |
const create = { | |
init (el, opts = {}) { | |
if (!(el instanceof HTMLElement)) { | |
console.log(el); |
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
// Link to code pen https://codepen.io/jaspercreel/pen/QMOepX | |
const secHand = document.getElementById('secHand'); | |
const minHand = document.getElementById('minHand'); | |
const hourHand = document.getElementById('hourHand'); | |
const start = -90; | |
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
/* | |
So let's say we're writing a program that will find the number of islands given a picture from a satellite. | |
The picture has already been pre-processed and encoded to a 2D matrix where 1 means land. And 0 means water. | |
How many islands are there? | |
*/ | |
// It is safe to assume the input will be an array of arrays and that the values are always 0, 1 | |
// It is worth noting that every 1 does not mean an individual island. 1's can connect to form a single landmass |
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
// Parts of this function were borrowed from http://blog.andrewray.me/how-to-clone-a-nested-array-in-javascript/ | |
// Link to code pen: https://codepen.io/jaspercreel/pen/jLmEWL | |
function trueClone(item) { | |
let copy, i; | |
if (Array.isArray(item)) { | |
copy = item.slice(0); | |
for (i = 0; i < copy.length; i++) { | |
copy[i] = trueClone(copy[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
function largestValuesInTreeRows(t) { | |
function depthSearch(current) { | |
let values = []; | |
let depth = 0; | |
function traverse(current, depth) { | |
if (!current) { | |
return; | |
} | |
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 kthLargestInBST(t, k) { | |
var check = function (value) { | |
k--; | |
if (k === 0) {return value;} | |
else {return false;} | |
} | |
var loop = function (node) { | |
if (!node) {return false} | |
return loop(node.left) || check(node.value) || loop(node.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
const Sorter = function (arr = [], key = null, def = null) { | |
state = { | |
arr, | |
key, | |
def | |
} | |
const proto = { | |
type: 'Sorter', |
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
// It is expected that the array will be sorted, otherwise you will not get a proper search | |
// code pen url: https://codepen.io/jaspercreel/pen/yoYYVN | |
const binSearch = (arr, key) => { | |
if (!Array.isArray(arr)) { | |
console.log('This binary search requires an array'); | |
return; | |
} | |
if (!key) { |
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
$breakpoints: ( | |
"phone": 400px, | |
"phone-wide": 480px, | |
"phablet": 560px, | |
"tablet-small": 640px, | |
"tablet": 768px, | |
"tablet-wide": 991px, | |
"desktop": 1200px, | |
"desktop-wide": 1440px | |
); |
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
/* | |
For this particular example the constraint is you cannot take two possibilities | |
that are next to each other. A real world example might be that you cannot invest multiple months | |
in a row and want to have the best chance at the best ROI. Kind of dumb but the point is | |
if there are constraints you want to track the best possible values for every sequence of moves, | |
only keeping track of the best possible outcomes | |
*/ | |
const bestOutcome = (arr) => { | |
NewerOlder