-
Notifications
You must be signed in to change notification settings - Fork 5
How to prevent cutting words? #11
Copy link
Copy link
Open
Description
Hi @hanwencheng ,
Let's say I have 2 strings to compare:
Thomas is playing footballThomas is playing futsal
Your library will return Thomas is playing f, which is logic in a way of substrings. But is there a way to consider words to not break them and return Thomas is playing (with space) or Thomas is playing f (with no space)?
Thank you,
EDIT: or if you have a suggestion of another library?
EDIT2: ended using the following:
const words1 = title1.split(' ');
const words2 = title2.split(' ');
let commonSubstring = '';
for (let i = 0; i < words1.length; i++) {
for (let j = 0; j < words2.length; j++) {
let tempSubstring = '';
let x = i;
let y = j;
while (x < words1.length && y < words2.length && words1[x] === words2[y]) {
tempSubstring += words1[x] + ' ';
x++;
y++;
}
if (tempSubstring.split(' ').length > commonSubstring.split(' ').length) {
commonSubstring = tempSubstring;
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels