Skip to content

How to prevent cutting words? #11

@sneko

Description

@sneko

Hi @hanwencheng ,

Let's say I have 2 strings to compare:

  • Thomas is playing football
  • Thomas 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;
      }
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions