Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: trekhleb/javascript-algorithms
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2863cb10440ac340f204812ef40f9da471fbf639
Choose a base ref
..
head repository: trekhleb/javascript-algorithms
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0e5c2e018a45b128d5b9493c3a2ab142937978cd
Choose a head ref
Showing with 3 additions and 2 deletions.
  1. +2 −1 src/algorithms/string/rabin-karp/__test__/rabinKarp.test.js
  2. +1 −1 src/algorithms/string/rabin-karp/rabinKarp.js
3 changes: 2 additions & 1 deletion src/algorithms/string/rabin-karp/__test__/rabinKarp.test.js
Original file line number Diff line number Diff line change
@@ -15,5 +15,6 @@ describe('rabinKarp', () => {
expect(rabinKarp('^ !/\'#\'pp', ' !/\'#\'pp')).toBe(1);
expect(rabinKarp('a\u{ffff}', '\u{ffff}')).toBe(1);
expect(rabinKarp('a\u{10000}', '\u{10000}')).toBe(1);
});
expect(rabinKarp('\u0000耀\u0000', '耀\u0000')).toBe(1);
});
});
2 changes: 1 addition & 1 deletion src/algorithms/string/rabin-karp/rabinKarp.js
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import RabinFingerprint from '../../../utils/hash/rolling/Rabin_Fingerprint';
export default function rabinKarp(text, word) {
const toNum = function toNum(character) {
const surrogate = character.codePointAt(1);
return ((surrogate === undefined) ? 0 : surrogate) | (character.codePointAt(0) << 16);
return ((surrogate === undefined) ? 0 : surrogate) + (character.codePointAt(0) * (2 ** 16));
};
const arrEq = (a1, a2) => ((a1.length === a2.length) && a1.every((val, idx) => val === a2[idx]));