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
printerError = (s) -> | |
goodAlphabet = "abcdefghijklm" | |
errorCount = 0 | |
for x in s | |
if x not in goodAlphabet then errorCount += 1 | |
"#{errorCount}/#{s.length}" |
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
array_diff = (a, b) -> | |
diff_array = [] | |
for e in a | |
if e not in b then diff_array.push e | |
diff_array |
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 maxSequence = function(arr){ | |
let isAllNegative = arr.every((e) => e < 0); | |
if (arr.length === 0 || isAllNegative) { | |
return 0; | |
} | |
let isAllPositive = arr.every((e) => e > 0); | |
if (isAllPositive) { | |
return arr.reduce((a,b) => { return a + b }, 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 decode(str) { | |
var result = []; | |
let idx = 0; | |
let charCount = 0; | |
let strCharCount = ''; | |
while (idx < str.length) { | |
if (str[idx] === '\\') { | |
// parse digits | |
strCharCount = ''; | |
idx += 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 sierpinski(n) { | |
if (n === 0) { | |
return 'L'; | |
} | |
let tri = sierpinski(n - 1); | |
let triRows = tri.split('\n'); | |
let gap = 2 * triRows.length - 1; | |
let arr = triRows.reduce((arr, r) => { | |
arr.push(r + ' '.repeat(gap) + r); |
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 convert(input, source, target) { | |
if (source === target) { | |
return input; | |
} | |
// Compute the value of the input in source base | |
// then convert it to value in target base | |
let sourceValue = input.split('').reverse().reduce( (acc, val, digitPos) => { | |
return acc + Math.pow(source.length, digitPos) * source.indexOf(val); | |
}, 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
// http://stackoverflow.com/questions/8002252/euler-project-18-approach | |
function longestSlideDown (pyramid) { | |
let pyramidSum = []; | |
pyramid.forEach((r, i) => { | |
pyramidSum.push(r.map((e) => { | |
return (i === pyramid.length - 1) ? e : 0; | |
})); | |
}); | |
for (let i = pyramidSum.length - 2; i >= 0; i--) { |
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 stripUrlParams(url, paramsToStrip){ | |
let [urlPath, urlParams] = url.split('?'); | |
let paramKVMap = {}; | |
let urlDistinctParams = '' | |
if (urlParams) { | |
urlParams.split('&').forEach((e) => { | |
let [key, val] = e.split('='); | |
if (!paramsToStrip || !paramsToStrip.includes(key)) { | |
if (!paramKVMap[key]) { |
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 getPINs(observed) { | |
// return [observed].concat(getPINsHelper(observed)); | |
// return getPINsHelper(observed); | |
let adjacentPins = { | |
'1': ['1','2','4'], | |
'2': ['1','2','3','5'], | |
'3': ['2','3','6'], | |
'4': ['1','4','5','7'], | |
'5': ['2','4','5','6','8'], | |
'6': ['3','5','6','9'], |
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
"use strict"; | |
var Observable = Rx.Observable; | |
var textbox = document.getElementById("textbox"); | |
var textArea = document.getElementById("results"); | |
var keypresses = Observable.fromEvent(textbox, 'keypress'); | |
keypresses.forEach(function (x) { |