Skip to content

Commit

Permalink
refactor: highlight after slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Nov 12, 2020
1 parent 2f24f10 commit 5d8cff4
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export function search<TItem extends RecentSearchesItem>({
limit,
}: SearchParams<TItem>): Array<Highlighted<TItem>> {
if (!query) {
return items.map((item) => highlight({ item, query })).slice(0, limit);
return items.slice(0, limit).map((item) => highlight({ item, query }));
}

return items
.filter((item) => item.query.toLowerCase().includes(query.toLowerCase()))
.map((item) => highlight({ item, query }))
.slice(0, limit);
.slice(0, limit)
.map((item) => highlight({ item, query }));
}

0 comments on commit 5d8cff4

Please sign in to comment.