mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-03-17 17:10:03 +01:00
Simplify the listSuggestions
with Array combinators
This commit is contained in:
parent
d49b252eb1
commit
aa2e5dd3af
1 changed files with 1 additions and 18 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue