REFACTOR: Remove `_.reject`

This commit is contained in:
Robin Ward 2020-09-01 13:47:22 -04:00
parent 2a4dfa83b0
commit 87b3caf927
2 changed files with 8 additions and 7 deletions

View File

@ -59,8 +59,10 @@ export default Controller.extend({
if (!q) {
return;
}
// remove l which can be used for sorting
return _.reject(q.split(/\s+/), t => t === "l").join(" ");
return q
.split(/\s+/)
.filter(t => t !== "l")
.join(" ");
},
@discourseComputed("skip_context", "context")

View File

@ -7,12 +7,11 @@ export const CLASS_NAME = "search-highlight";
export default function(elem, term, opts = {}) {
if (!isEmpty(term)) {
// special case ignore "l" which is used for magic sorting
let words = _.reject(
term.match(new RegExp(`${SEARCH_PHRASE_REGEXP}|[^\\s]+`, "g")),
t => t === "l"
);
let words = term
.match(new RegExp(`${SEARCH_PHRASE_REGEXP}|[^\\s]+`, "g"))
.filter(t => t !== "l")
.map(w => w.replace(/^"(.*)"$/, "$1"));
words = words.map(w => w.replace(/^"(.*)"$/, "$1"));
const highlightOpts = {};
if (!opts.defaultClassName) highlightOpts.className = CLASS_NAME;
highlightHTML(elem, words, highlightOpts);