|
@@ -2,17 +2,17 @@
|
2
|
2
|
* Implements a simple hash code for a string (see
|
3
|
3
|
* https://en.wikipedia.org/wiki/Java_hashCode()).
|
4
|
4
|
*
|
5
|
|
- * @param {string} The string to return a hash of.
|
6
|
|
- * @return {Number} the integer hash code of the string.
|
|
5
|
+ * @param {string} string - The string to return a hash of.
|
|
6
|
+ * @return {number} the integer hash code of the string.
|
7
|
7
|
*/
|
8
|
|
-function integerHash(string) {
|
|
8
|
+function integerHash(string: string): number {
|
9
|
9
|
if (!string) {
|
10
|
10
|
return 0;
|
11
|
11
|
}
|
12
|
12
|
|
13
|
|
- let char, hash = 0, i;
|
|
13
|
+ let char: number, hash = 0;
|
14
|
14
|
|
15
|
|
- for (i = 0; i < string.length; i++) {
|
|
15
|
+ for (let i = 0; i < string.length; i++) {
|
16
|
16
|
char = string.charCodeAt(i);
|
17
|
17
|
hash += char * Math.pow(31, string.length - 1 - i);
|
18
|
18
|
hash = Math.abs(hash | 0); // eslint-disable-line no-bitwise
|
|
@@ -21,4 +21,4 @@ function integerHash(string) {
|
21
|
21
|
return hash;
|
22
|
22
|
}
|
23
|
23
|
|
24
|
|
-module.exports = { integerHash };
|
|
24
|
+export default integerHash;
|