From a4c4b05dadcee5e958df96574d1045e17cb73b45 Mon Sep 17 00:00:00 2001 From: fauzan171 Date: Sun, 7 Jun 2026 00:11:24 +0700 Subject: [PATCH] refactor: replace deprecated String.prototype.substr() with substring() String.prototype.substr() is deprecated and may be removed in future JavaScript engine versions (Annex B of the ECMAScript specification). Replaced all occurrences in the codebase with String.prototype.substring(): - src/algorithms/string/rabin-karp/rabinKarp.js - src/algorithms/cryptography/polynomial-hash/__test__/SimplePolynomialHash.test.js - src/algorithms/cryptography/polynomial-hash/__test__/PolynomialHash.test.js The behavior is identical since all substr(start, length) calls are converted to substring(start, start + length) with the same arguments. All existing tests pass. --- .../polynomial-hash/__test__/PolynomialHash.test.js | 4 ++-- .../polynomial-hash/__test__/SimplePolynomialHash.test.js | 4 ++-- src/algorithms/string/rabin-karp/rabinKarp.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/algorithms/cryptography/polynomial-hash/__test__/PolynomialHash.test.js b/src/algorithms/cryptography/polynomial-hash/__test__/PolynomialHash.test.js index 0d487848dc..960ff03864 100644 --- a/src/algorithms/cryptography/polynomial-hash/__test__/PolynomialHash.test.js +++ b/src/algorithms/cryptography/polynomial-hash/__test__/PolynomialHash.test.js @@ -21,12 +21,12 @@ describe('PolynomialHash', () => { // Check hashing for different word lengths. frameSizes.forEach((frameSize) => { - let previousWord = text.substr(0, frameSize); + let previousWord = text.substring(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.substring(frameShift, frameShift + frameSize); const currentHash = polynomialHash.hash(currentWord); const currentRollingHash = polynomialHash.roll(previousHash, previousWord, currentWord); diff --git a/src/algorithms/cryptography/polynomial-hash/__test__/SimplePolynomialHash.test.js b/src/algorithms/cryptography/polynomial-hash/__test__/SimplePolynomialHash.test.js index 28c551966d..ffb7530387 100644 --- a/src/algorithms/cryptography/polynomial-hash/__test__/SimplePolynomialHash.test.js +++ b/src/algorithms/cryptography/polynomial-hash/__test__/SimplePolynomialHash.test.js @@ -18,12 +18,12 @@ describe('PolynomialHash', () => { // Check hashing for different word lengths. frameSizes.forEach((frameSize) => { - let previousWord = text.substr(0, frameSize); + let previousWord = text.substring(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.substring(frameShift, frameShift + frameSize); const currentHash = polynomialHash.hash(currentWord); const currentRollingHash = polynomialHash.roll(previousHash, previousWord, currentWord); diff --git a/src/algorithms/string/rabin-karp/rabinKarp.js b/src/algorithms/string/rabin-karp/rabinKarp.js index 9084eb4084..65c3e44859 100644 --- a/src/algorithms/string/rabin-karp/rabinKarp.js +++ b/src/algorithms/string/rabin-karp/rabinKarp.js @@ -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.substring(charIndex, charIndex + word.length) === word ) { return charIndex; }