Guest User

Untitled

a guest
Apr 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. // Remove disabling when there is more than one export in the file.
  2. // eslint-disable-next-line import/prefer-default-export
  3. export const highlightCommonTerms2 = function highlightCommonTerms2(text, terms) {
  4. const termTokens = terms.split(/[^a-zA-Z0-9_-]+/);
  5. const textTokens = text.split(" ");
  6. // can we do an "includes" that works on substrings? Otherwise write your own checker
  7. return (
  8. <span>
  9. {textTokens.map((textElem, idx) => (
  10. termTokens.some(arrElem => (textElem.replace(/\W/g, '') === arrElem)) ?
  11. (<strong key={idx}>{textElem} </strong>) : // eslint-disable-line react/no-array-index-key
  12. (<span key={idx}>{textElem} </span>) // eslint-disable-line react/no-array-index-key
  13. ))}
  14. </span>
  15. );
  16. };
Add Comment
Please, Sign In to add comment