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
class RomanNumerals
literalMap = {
'I' : 1,
'V' : 5,
'X' : 10,
'L' : 50,
'C' : 100,
'D' : 500,
'M' : 1000
LCS = (x, y) ->
lcsArray = []
lcsSeqArray = []
longestSeq = ''
longestLength = -1
for i in [0..x.length]
t = []
s = []
for j in [0..y.length]
t.push(0)
calc = (expr) ->
# Your awesome code here
if expr is "" then return 0
stack = []
tokens = expr.split(' ')
for token in tokens
if token in ['+','-', '*', '/']
# pop the last two values, calculate the total and push the result back
operands = stack.splice(stack.length - 2, 2)
result = 0
function loop_size(node){
var visitedNodes = [];
var idx = -1;
while (node != null) {
idx = visitedNodes.indexOf(node);
if (idx < 0) {
visitedNodes.push(node);
} else {
break;
}
Array.prototype.sameStructureAs = function (other) {
// Return 'true' if and only if 'other' has the same
// nesting structure as 'this'.
// Note: You are given a function isArray(o) that returns
// whether its argument is an array.
if (this.length !== other.length) {
return false;
}
for (var i = 0; i < this.length; i++) {
function solution(input, markers){
var comments = input.split('\n');
for (var i in markers) {
for (var j in comments) {
var line = null;
var idx = comments[j].indexOf(markers[i]);
if (idx >= 0) {
comments[j] = comments[j].substring(0, idx).trim();
}
}
function VendingMachine(coins) {
this.coins = coins;
}
VendingMachine.prototype.calculateCredit = function(credit) {
var total_credit = 0;
for (var value in credit) {
if ((this.coins[value] != null) || (typeof this.coins[value] !== "undefined")) {
total_credit += value * credit[value];
}
// Sorry, I cheated.
// Idea comes from http://www.geeksforgeeks.org/factorial-large-number/
function factorial(n){
// Add some code
if (n < 0) { return null; }
var factArray = [1];
var factSize = 1;
var carry;
var prod;
function isValidCoordinates(coordinates){
var coordinatesReg = /^(-?\d+(\.\d+)?),\s*(-?\d+(\.\d+)?)$/g
if (!coordinatesReg.test(coordinates)) {
return false;
}
var arrCoordinates = coordinates.split(',');
try {
var strLat = arrCoordinates[0].trim();
decodeMorse = function(morseCode){
var decodeString = '';
var morseCodeWords = morseCode.split(' ');
for (var i in morseCodeWords) {
var morseCodeArray = morseCodeWords[i].split(' ');
for (var j in morseCodeArray) {
if (MORSE_CODE[morseCodeArray[j]] !== undefined) {
decodeString += MORSE_CODE[morseCodeArray[j]];
}
}