Created
January 3, 2014 16:12
-
-
Save foliveira/e2870850284ff136f4d1 to your computer and use it in GitHub Desktop.
Price calculation based on a Index-Tree in Javascript (of Phone Numbers)
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
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