This file contains 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
# Filed under: 140bytes, fibonacci, recursive | |
# calculate fibonacci (recursively) | |
fibonacci = (n) -> | |
if n > 1 then f(n - 1) + f(n - 2) else n |
This file contains 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
# Filed under: hex, color, rgb | |
# Converts a hex string to RGB. | |
### | |
@param a a "#xxxxxx" hex string, | |
### | |
hex2rgb = (a) -> | |
### | |
turn it into a number by taking the hexadecimal prefix and the |
This file contains 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
# Filed under: color, convert, hsl, rgb | |
# Converts hue-saturation-lightness to red-green-blue color value. | |
### | |
@param a hue | |
@param b saturation | |
@param c lightness | |
### | |
hsl2rgb = (a, b, c) -> |
This file contains 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
# Filed under: 140bytes, identifier, object, id, hashcode | |
# Gives every object a unique ID. | |
(() -> | |
Object.prototype.getHashCode = ((i) -> | |
i = 0 | |
() -> | |
if this.h = this.h then this.h else i++ | |
)() |
This file contains 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
# Filed under: uuid, id, random | |
### | |
a: placeholder | |
### | |
b = (a) -> | |
### | |
if the placeholder was passed, return a random number from 0 to 15 unless b | |
is 8, in which case a random number from 8 to 11 in hexadecimal or |
This file contains 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
def square_root(num): | |
return num ** 0.5 |
This file contains 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
{"index.js":"function rot13(str) { // LBH QVQ VG!\n return str.split('')\n .map.call(str, function(char) {\n \n let x = char.charCodeAt(0);\n \n if (x < 65 || x > 90) { \n return String.fromCharCode(x);\n } else if (x < 78) { \n return String.fromCharCode(x + 13); \n }\n \n return String.fromCharCode(x - 13);\n }).join(''); \n}\n\n// Change the inputs below to test\nrot13(\"SERR PBQR PNZC\");"} |
This file contains 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
{"index.js":"\nvar denominations = [\n { name: 'ONE HUNDRED', val: 100.00},\n { name: 'TWENTY', val: 20.00},\n { name: 'TEN', val: 10.00},\n { name: 'FIVE', val: 5.00},\n { name: 'ONE', val: 1.00},\n { name: 'QUARTER', val: 0.25},\n { name: 'DIME', val: 0.10},\n { name: 'NICKEL', val: 0.05},\n { name: 'PENNY', val: 0.01}\n];\n\nfunction checkCashRegister(price, cash, cid) {\n var result = { status: null, change: [] };\n var change = cash - price;\n\n var register = cid.reduce(function(acc, curr) {\n acc.total += curr[1];\n acc[curr[0]] = curr[1];\n return acc;\n }, { total: 0 });\n\n if (register.total === change) {\n result.status = 'CLOSED';\n result.change = cid;\n return result;\n }\n\n // Handle obvious insufficient funds\n if (register.total < change) {\n result.status = 'INSUFFICIENT_FUNDS';\n return result;\n }\n\n var change_arr = denominations.reduce(function(acc, curr) {\n var value = 0;\n \n while (register[curr.name] > 0 && change >= curr.val) { |
This file contains 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
{"index.js":"function palindrome(str) {\n return str.replace(/[\\W_]/g, '').toLowerCase() ===\n str.replace(/[\\W_]/g, '')\n .toLowerCase()\n .split('')\n .reverse()\n .join('');\n}\n\npalindrome(\"eye\");"} |
This file contains 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
{"index.js":"function convertToRoman(num) {\n\n var decVal = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ];\n var romanVal = [ 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I' ];\n\n var romanized = '';\n\n for (var index = 0; index < decVal.length; index++) {\n while (decVal[index] <= num) {\n romanized += romanVal[index];\n num -= decVal[index];\n }\n }\n\n return romanized;\n }\n\nconvertToRoman(36);"} |
OlderNewer