The Doc Dialer, Part 2: A Browser Independent Version: The Global Area | WebReference

The Doc Dialer, Part 2: A Browser Independent Version: The Global Area

The Doc Dialer, Part 2: A Browser Independent Version

The Global Area

The global variables include five arrays: empList, keyMap, empPhone, tree, and printList. The size of the data-dependent arrays is determined by EMPMAX which is initialized to 10,000. The empList array holds the Doc Dialer's entries. When the application loads, it includes just eight names. Any new entry is added to this array. The names stored in empList preserve the case entered by the user. Since the phone's keypad includes only upper case characters, all matching functions are case-insensitive. The variable lastEmp points to the last name entered to empList. Here are the corresponding lines in the script:

var EMPMAX = 10000;
var empList = new Array(EMPMAX);
empList[1] = "Ronald Reagan"; 
empList[2] = "Jimmy Carter";  
empList[3] = "Richard Nixon";
empList[4] = "Bill Clinton"; 
empList[5] = "Gerald Ford"; 
empList[6] = "George Bush";  
empList[7] = "Lyndon Johnson"; 
empList[8] = "John Kennedy";  
var lastEmp = 8;

The empPhone array holds an extension for every entry in empList. When you enter an extension for a new entry, the Doc Dialer expects a 4-digit entry only. Here are the corresponding lines in the script:

var empPhone = new Array(EMPMAX);
empPhone[1] = 5808;
empPhone[2] = 5919;
empPhone[3] = 5303;
empPhone[4] = 5606;
empPhone[5] = 5707;
empPhone[6] = 5313;
empPhone[7] = 5838;
empPhone[8] = 5006;

The keyMap array is an associative array. Instead of the regular array's numeric indices, the associative array's indices are strings. We have here a classic usage for an associative array: translate each character of the alphabet to the corresponding numeric key on the phone keypad. Here are the corresponding lines:

var keyMap = new Array(24);
keyMap["A"] = "2";
keyMap["B"] = "2";
keyMap["C"] = "2";
keyMap["D"] = "3";
keyMap["E"] = "3";
keyMap["F"] = "3";
keyMap["G"] = "4";
keyMap["H"] = "4";
keyMap["I"] = "4";
keyMap["J"] = "5";
keyMap["K"] = "5";
keyMap["L"] = "5";
keyMap["M"] = "6";
keyMap["N"] = "6";
keyMap["O"] = "6";
keyMap["P"] = "7";
keyMap["R"] = "7";
keyMap["S"] = "7";
keyMap["T"] = "8";
keyMap["U"] = "8";
keyMap["V"] = "8";
keyMap["W"] = "9";
keyMap["X"] = "9";
keyMap["Y"] = "9";

Notice again that the phone keypad does not support the Q and Z characters. You have to use similarly-pronounced characters instead (K and X for example).

The trie data structure starts with a 10-element array at the top:

var tree = new Array(10);

The last array is the printList array which we covered in Column 57. Entries that are about to be printed are flagged as true in this array. All other entries are false.

Next: How to initialize the Doc Dialer

Produced by Yehuda Shiran and Tomer Shiran

Created: February 28, 2000
Revised: April 26, 2000