That should about do it! Let's try it out.
Complexity for Final Solution
The hash map data structure grows linearly to hold n elements for O(n) linear space complexity. Assuming a good hash function (one that minimizes collisions!) we usually have O(1) constant get/set complexity. Otherwise, in the worst case where all n entries hash to the same bucket we traverse through for an unfortunate O(n) linear get/set complexity.
xxxxxxxxxx70
"`var dict = new Hashmap(); dict.set('jess', '213-559-6840'); dict.set('james', '123-456-7890'); dict.get('james')` should return `'123-456-7890'`"var assert = require('assert');class Hashmap { constructor() { // implement this } set(key, val) { // implement this } get(key) { // implement this } hashStr(str) { let finalHash = 0; for (let i = 0; i < str.length; i++) { const charCode = str.charCodeAt(i); finalHash += charCode; } return finalHash; }}try { var dict = new Hashmap();OUTPUT
Results will appear here.