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
prefixString = "* + 2 3 4" | |
evaluatePrefix = (prefix)-> | |
operator = prefix.shift() | |
leftValue = if isNaN parseFloat prefix[0] then evaluatePrefix prefix else prefix.shift() | |
rightValue = if isNaN parseFloat prefix[0] then evaluatePrefix prefix else prefix.shift() | |
eval leftValue+operator+rightValue | |
prefix = prefixString.split ' ' | |
console.log evaluatePrefix prefix |
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
isAnagram = (a,b)-> | |
if a.length != b.length | |
return false | |
[a,b] = [a,b].map (x)->x.toLowerCase().split('') | |
length = a.length | |
if length > 12852 | |
throw new Error "This algorithm can only reliably handle strings smaller than 12,852 characters" | |
anagramHash = (hash, letter)-> | |
charCode = letter.charCodeAt(0)-96 | |
if !(1 <= charCode <= 26) |
NewerOlder