Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please give a detailed explanation of your answer. Thanks. Solution Hash tables

ID: 3633672 • Letter: P

Question

Please give a detailed explanation of your answer. Thanks.

Explanation / Answer

Hash tables are a permutation of associative arrays (i.e. name => value pairs). If you use PHP, then you are very familiar with this type of data structure already since all PHP arrays are associative. The Javascript language implements very loose and somewhat limited support for associative arrays. Any JavaScript array can use other objects as keys, making it a hash, but there exists no formal constructor for initializing them and it is more or less unweildy to work with. A short example of a hash in JavaScript would be as follows: var myArray = new Array(); myArray['one'] = 1; myArray['two'] = 2; myArray['three'] = 3; // show the values stored for (var i in myArray) { alert('key is: ' + i + ', value is: ' + myArray[i]); } Just as in PHP, the 'foreach' contruct is used to run through the array, doing something for each key => value pair. However, notice I did not do: for (var i = 0; i