Skip to content
This repository was archived by the owner on May 1, 2023. It is now read-only.

Commit 2718c82

Browse files
committed
Changed legacy function substr() to substring()
1 parent ccdb537 commit 2718c82

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

compare-strings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function compareTwoStrings(first, second) {
1515

1616
let firstBigrams = new Map();
1717
for (let i = 0; i < first.length - 1; i++) {
18-
const bigram = first.substr(i, 2);
18+
const bigram = first.substring(i, i + 2);
1919
const count = firstBigrams.has(bigram)
2020
? firstBigrams.get(bigram) + 1
2121
: 1;
@@ -25,7 +25,7 @@ function compareTwoStrings(first, second) {
2525

2626
let intersectionSize = 0;
2727
for (let i = 0; i < second.length - 1; i++) {
28-
const bigram = second.substr(i, 2);
28+
const bigram = second.substring(i, i + 2);
2929
const count = firstBigrams.has(bigram)
3030
? firstBigrams.get(bigram)
3131
: 0;

test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const comp = require('./compare-strings.js');
2+
3+
let robles = comp.compareTwoStrings('Olive-green table for sale, in extremely good condition.','For sale: green Subaru Impreza, 210,000 miles')
4+
5+
console.log(robles);

0 commit comments

Comments
 (0)