Turn a string into a number
Make a folder with a package.json that sets "type": "module", so Node treats your .ts files as ES modules.
hash.ts walks the key one character at a time: multiply the total by 31, add the character code. >>> 0 keeps the result a whole number from 0 to 2³² − 1.
WHY
A map needs one thing from a key: the same number every time you ask. cat gives 98262 on every run, and act, with the same letters, gives a different number because the order changes the sum. Java’s String.hashCode uses the same multiplier, 31.