Skip to content

Commit

Permalink
perf: use flatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash-Singh1 committed Jan 3, 2024
1 parent 3d06958 commit 4ac0a65
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/utils/createValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,9 @@ export function createValidator({
matchingMetadataKeyIndex.push(+metadataKeyIndex);
}
}
const attributeValues = matchingMetadataKeyIndex
.map((index) => metadata[metadataKeys[index]])
.reduce(
(accumalator: Metadata[], metadataPart) =>
Array.isArray(metadataPart)
? [...accumalator, ...metadataPart]
: [...accumalator, metadataPart],
[] as Metadata[]
);
const attributeValues = matchingMetadataKeyIndex.flatMap(
(index) => metadata[metadataKeys[index]]
);
validator({
attrVal: attributeValues,
index: [...attributeValues.keys()],
Expand Down

0 comments on commit 4ac0a65

Please sign in to comment.