(word)
| 60 | }; |
| 61 | |
| 62 | const getHash = (word) => { |
| 63 | const frequency = new Array(26).fill(0); |
| 64 | |
| 65 | for (const char of word) { |
| 66 | /* Time O(K) */ |
| 67 | const charCode = getCode(char); /* Time O(1) | Space (1) */ |
| 68 | |
| 69 | frequency[charCode]++; /* | Space O(1) */ |
| 70 | } |
| 71 | |
| 72 | return buildHash(frequency); |
| 73 | }; |
| 74 | |
| 75 | const getCode = (char) => char.charCodeAt(0) - 'a'.charCodeAt(0); |
| 76 |
no test coverage detected