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
// 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 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];
}
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();
}
}
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 loop_size(node){
var visitedNodes = [];
var idx = -1;
while (node != null) {
idx = visitedNodes.indexOf(node);
if (idx < 0) {
visitedNodes.push(node);
} else {
break;
}
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
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)
class RomanNumerals
literalMap = {
'I' : 1,
'V' : 5,
'X' : 10,
'L' : 50,
'C' : 100,
'D' : 500,
'M' : 1000
class UriBuilder
constructor: (@url) ->
@params = {}
idx = @url.indexOf('?')
if idx >= 0
lstParams = @url.substring(idx + 1)
@url = @url.substring(0, idx)
paramPairs = lstParams.split('&')
function nbMonths(startPriceOld, startPriceNew, savingperMonth, percentLossByMonth) {
//your code here
if (startPriceOld >= startPriceNew) {
return [0, Math.floor(startPriceOld - startPriceNew)];
}
let months = 0;
let totalSaving = 0;
let depreciatedPriceNew = startPriceNew;
let depreciatedPriceOld = startPriceOld;