From aa2e5dd3af7bbf976ff937a8266a21c4b3b3cbb8 Mon Sep 17 00:00:00 2001 From: MareStare Date: Thu, 13 Mar 2025 22:32:12 +0000 Subject: [PATCH] Simplify the `listSuggestions` with Array combinators --- assets/js/autocomplete/history/history.ts | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/assets/js/autocomplete/history/history.ts b/assets/js/autocomplete/history/history.ts index cf43cc2d..aca06129 100644 --- a/assets/js/autocomplete/history/history.ts +++ b/assets/js/autocomplete/history/history.ts @@ -71,23 +71,6 @@ export class InputHistory { } listSuggestions(query: string, limit: number): string[] { - // Waiting for iterator combinators such as `Iterator.prototype.filter()` - // and `Iterator.prototype.take()` to reach a greater availability 🙏: - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/filter - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/take - - const results = []; - - for (const record of this.records) { - if (results.length >= limit) { - break; - } - - if (record.startsWith(query)) { - results.push(record); - } - } - - return results; + return this.records.filter(record => record.startsWith(query)).slice(0, limit); } }