Skip to content

Instantly share code, notes, and snippets.

@foliveira
Created January 3, 2014 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foliveira/e2870850284ff136f4d1 to your computer and use it in GitHub Desktop.
Save foliveira/e2870850284ff136f4d1 to your computer and use it in GitHub Desktop.
Price calculation based on a Index-Tree in Javascript (of Phone Numbers)
function Process(num, h) {
var first_num = num.charAt(0)
var following_nums = num.slice(1)
var first_num_hash_hit = h[first_num]
var following_nums_lookahead = following_nums.charAt(0)
if(!first_num_hash_hit.hasOwnProperty(following_nums_lookahead))
return null
if(following_nums.length === 0)
return first_num_hash_hit.value
if(h.hasOwnProperty(first_num))
return Process(following_nums, first_num_hash_hit) || first_num_hash_hit[following_nums_lookahead].value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment