This file contains hidden or 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 solution(Y, A, B, W) { | |
// write your code in JavaScript (Node.js 8.9.4) | |
const MONTH_DAYS = { | |
"January":31, "February":28, "March":31, "April":30, "May":31, "June":30, "July":31, "August":31, "September":30, "October":31, "November":30, "December":31 | |
}; | |
const MONTHS = { | |
"January":0, "February":1, "March":2, "April":3, "May":4, "June":5, "July":6, "August":7, "September":8, "October":9, "November":10, "December":11 | |
}; | |
function findFirstVacationMonday(year, month) { |
This file contains hidden or 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 isOneSwapSort(A){ | |
for ( let f = A.length - 1; f > 0; f--) { | |
for (let i=0; i<f; i++) { | |
if ( A[f] < A[i] ){ | |
let temp = A[i]; | |
A[i] = A[f]; | |
A[f] = temp; | |
if ( isOneSwapSort(A) > 0 ) return 2; //more than one swap | |
return 1; //one swap | |
} |
This file contains hidden or 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 callWhenReady(testCB, readyCB) { | |
console.log('checking for page ready'); | |
var i = setInterval(function(){ // after 1/4 of a sec | |
var res = testCB(); | |
if (res === true){ // wait X sec if node count does not change, page likely finished loading. | |
clearInterval(i); | |
readyCB(); | |
} | |
}, 250); | |
} |
This file contains hidden or 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 solution(A) { | |
var red = A => A.reduce((res, val) => res+val); | |
for (i=0; i<A.length; i++){ | |
var z = i | |
for (j=0, z=i; j<=i; j++, z--){ | |
x = red(A.slice(j, A.length-z)); | |
if (x>=0) return A.length-z-j; | |
} | |
} | |
return 0; |
This file contains hidden or 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 smallInt(A) { | |
let s = 1; | |
A.sort((a, b) => a - b) | |
if (A[0] >= 0) { | |
if (A.indexOf(1) === -1) { | |
return 1; | |
} | |
} | |
for (i=0; i<A.length; i++){ | |
s = A[i]+1; |
This file contains hidden or 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 callWhenReady(callBack, sec) { | |
var wait4Loop = ( sec || 5 ) * 4; | |
var loopNum = 0; | |
var domCount = document.querySelectorAll('*').length; //count DOM elements | |
var i = setInterval(function(){ // after 1/4 of a sec | |
var newCount = document.querySelectorAll('*').length; //count DOM elements | |
if (domCount != newCount){ // new DOM elements are counted, page still loading | |
domCount = newCount; | |
loopNum = 0; | |
}else{ // wait X sec if node count does not change, page likely finished loading. |
This file contains hidden or 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
// taken from https://www.sitepoint.com/object-oriented-javascript-deep-dive-es6-classes/ | |
let SimpleDate = (function() { | |
let _years = new WeakMap(); | |
let _months = new WeakMap(); | |
let _days = new WeakMap(); | |
class SimpleDate { | |
constructor(year, month, day) { | |
// Check that (year, month, day) is a valid date | |
// ... |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>React Timer</title> | |
<script src="https://unpkg.com/[email protected]/dist/react.js"></script> | |
<script src="https://unpkg.com/[email protected]/dist/react-dom.js"></script> | |
<script src="https://unpkg.com/[email protected]/babel.min.js"></script> | |
</head> | |
<body> |
This file contains hidden or 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 id = (Math.random() * (1000000000 - 1) + 1 | 0) + ":" + (new Date().getTime()) |
This file contains hidden or 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
//invokes segments of an asynchronus function | |
function asyncF(generator) { | |
try { | |
var steps = generator(); // function to exec by segments | |
return iterate(steps.next()); | |
} catch(e) { | |
return Promise.reject(e); // rejects iteration | |
} | |
function iterate({value, done}) { // arg has value of prev iteration | |
if (done) return Promise.resolve(value); // resolves all pending promises |