Skip to content

Commit

Permalink
Use largest word for emoji matching
Browse files Browse the repository at this point in the history
  • Loading branch information
bas080 committed Jun 27, 2024
1 parent fb65cdf commit ffad821
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lit-component.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ import {
moveItemToTop,
} from "./util.mjs";

const largestWord = (str) => {
return str.split(" ").reduce((largest, currentWord) => {
return currentWord.length > largest.length ? currentWord : largest;
}, "");
};

// Example usage:
console.log(largestWord("The quick brown fox jumps over the lazy dog")); // Output: "jumps"

const svg = {
flame: html`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.-->
Expand Down Expand Up @@ -127,7 +136,7 @@ const someEmoji = memoize((value) => {
if (!value) return null;

return findMax(([tag]) => {
return -levenshtein(tag, value);
return -levenshtein(tag, largestWord(value));
}, emojiByTag)[1].unicode;
});

Expand Down

0 comments on commit ffad821

Please sign in to comment.