aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2023-11-07 17:26:27 +0100
committerGitHub <[email protected]>2023-11-07 16:26:27 +0000
commit8542ef30bd4eda3d9f04db2c4a79abf0369d57c3 (patch)
tree94f768aa2c1c48faedddb745843f6d0b34b19988 /src/modules
parent9498203190e37a96114ddc8e861b02ccd94e517b (diff)
downloadfaker-8542ef30bd4eda3d9f04db2c4a79abf0369d57c3.tar.xz
faker-8542ef30bd4eda3d9f04db2c4a79abf0369d57c3.zip
infra(unicorn): no-array-reduce (#2479)
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/word/filter-word-list-by-length.ts10
1 files changed, 2 insertions, 8 deletions
diff --git a/src/modules/word/filter-word-list-by-length.ts b/src/modules/word/filter-word-list-by-length.ts
index 60c6fae9..f3fcd5ab 100644
--- a/src/modules/word/filter-word-list-by-length.ts
+++ b/src/modules/word/filter-word-list-by-length.ts
@@ -1,4 +1,5 @@
import { FakerError } from '../../errors/faker-error';
+import { groupBy } from '../../internal/group-by';
/**
* The error handling strategies for the `filterWordListByLength` function.
@@ -13,14 +14,7 @@ const STRATEGIES = {
wordList: ReadonlyArray<string>,
length: { min: number; max: number }
): string[] => {
- const wordsByLength = wordList.reduce<Record<number, string[]>>(
- (data, word) => {
- (data[word.length] = data[word.length] ?? []).push(word);
- return data;
- },
- {}
- );
-
+ const wordsByLength = groupBy(wordList, (word) => word.length);
const lengths = Object.keys(wordsByLength).map(Number);
const min = Math.min(...lengths);
const max = Math.max(...lengths);