Skip to content

Instantly share code, notes, and snippets.

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
@timhuff
timhuff / gist:5b5a72e47549b522e126
Created February 19, 2015 12:44
Algorithm for testing if two strings of the form /[A-Z][a-z]*/ are anagrams
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)