From a87798bb8ec40abc87f4b75cfc5c24c4e090f4e9 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 28 Jan 2020 17:04:25 +0000 Subject: [PATCH] refactor: Use Set for popular emojis. --- static/shared/js/typeahead.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/static/shared/js/typeahead.js b/static/shared/js/typeahead.js index 55a3bea1ae..c31ab55cd4 100644 --- a/static/shared/js/typeahead.js +++ b/static/shared/js/typeahead.js @@ -147,6 +147,8 @@ exports.triage = function (query, objs, get_item) { }; exports.sort_emojis = function (objs, query) { + const popular_set = new Set(exports.popular_emojis); + const triage_results = exports.triage( query, objs, @@ -157,7 +159,7 @@ exports.sort_emojis = function (objs, query) { const other_emoji_matches = []; for (const obj of triage_results.matches) { - if (exports.popular_emojis.indexOf(obj.emoji_code) !== -1) { + if (popular_set.has(obj.emoji_code)) { popular_emoji_matches.push(obj); } else { other_emoji_matches.push(obj);