Skip to content

Instantly share code, notes, and snippets.

View railsstudent's full-sized avatar
🏠
Researching third-party library

Connie Leung railsstudent

🏠
Researching third-party library
View GitHub Profile
printerError = (s) ->
goodAlphabet = "abcdefghijklm"
errorCount = 0
for x in s
if x not in goodAlphabet then errorCount += 1
"#{errorCount}/#{s.length}"
array_diff = (a, b) ->
diff_array = []
for e in a
if e not in b then diff_array.push e
diff_array
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);
}
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;
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);
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);
// 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--) {
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]) {
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'],
"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) {