Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Remove disabling when there is more than one export in the file.
- // eslint-disable-next-line import/prefer-default-export
- export const highlightCommonTerms2 = function highlightCommonTerms2(text, terms) {
- const termTokens = terms.split(/[^a-zA-Z0-9_-]+/);
- const textTokens = text.split(" ");
- // can we do an "includes" that works on substrings? Otherwise write your own checker
- return (
- <span>
- {textTokens.map((textElem, idx) => (
- termTokens.some(arrElem => (textElem.replace(/\W/g, '') === arrElem)) ?
- (<strong key={idx}>{textElem} </strong>) : // eslint-disable-line react/no-array-index-key
- (<span key={idx}>{textElem} </span>) // eslint-disable-line react/no-array-index-key
- ))}
- </span>
- );
- };
Add Comment
Please, Sign In to add comment