Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also 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: master
Choose a base ref
...
head repository: CommanderRoot/javascript-algorithms
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: rm-deprecated-substr
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Feb 18, 2022

  1. Replace deprecated String.prototype.substr()

    String.prototype.substr() is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) so we replace it with slice() which works similarily but isn't deprecated.
    Signed-off-by: Tobias Speicher <[email protected]>
    CommanderRoot committed Feb 18, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    7615da1 View commit details
Original file line number Diff line number Diff line change
@@ -21,12 +21,12 @@ describe('PolynomialHash', () => {

// Check hashing for different word lengths.
frameSizes.forEach((frameSize) => {
let previousWord = text.substr(0, frameSize);
let previousWord = text.slice(0, frameSize);
let previousHash = polynomialHash.hash(previousWord);

// Shift frame through the whole text.
for (let frameShift = 1; frameShift < (text.length - frameSize); frameShift += 1) {
const currentWord = text.substr(frameShift, frameSize);
const currentWord = text.slice(frameShift, frameShift + frameSize);
const currentHash = polynomialHash.hash(currentWord);
const currentRollingHash = polynomialHash.roll(previousHash, previousWord, currentWord);

Original file line number Diff line number Diff line change
@@ -18,12 +18,12 @@ describe('PolynomialHash', () => {

// Check hashing for different word lengths.
frameSizes.forEach((frameSize) => {
let previousWord = text.substr(0, frameSize);
let previousWord = text.slice(0, frameSize);
let previousHash = polynomialHash.hash(previousWord);

// Shift frame through the whole text.
for (let frameShift = 1; frameShift < (text.length - frameSize); frameShift += 1) {
const currentWord = text.substr(frameShift, frameSize);
const currentWord = text.slice(frameShift, frameShift + frameSize);
const currentHash = polynomialHash.hash(currentWord);
const currentRollingHash = polynomialHash.roll(previousHash, previousWord, currentWord);

2 changes: 1 addition & 1 deletion src/algorithms/string/rabin-karp/rabinKarp.js
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ export default function rabinKarp(text, word) {
// In case of hash collision the strings may not be equal.
if (
wordHash === currentFrameHash
&& text.substr(charIndex, word.length) === word
&& text.slice(charIndex, charIndex + word.length) === word
) {
return charIndex;
}