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
| class RomanNumerals | |
| literalMap = { | |
| 'I' : 1, | |
| 'V' : 5, | |
| 'X' : 10, | |
| 'L' : 50, | |
| 'C' : 100, | |
| 'D' : 500, | |
| 'M' : 1000 |
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
| 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) |
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
| 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 |
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 loop_size(node){ | |
| var visitedNodes = []; | |
| var idx = -1; | |
| while (node != null) { | |
| idx = visitedNodes.indexOf(node); | |
| if (idx < 0) { | |
| visitedNodes.push(node); | |
| } else { | |
| break; | |
| } |
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.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++) { |
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(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(); | |
| } | |
| } |
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 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]; | |
| } |
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
| // 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; |
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 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(); |
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
| 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]]; | |
| } | |
| } |