Skip to content

Commit

Permalink
perf: slightly improve performance by not using for..of
Browse files Browse the repository at this point in the history
  • Loading branch information
changwoolab committed Jul 16, 2024
1 parent 3dd8009 commit 72a21e1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/object/invert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
export function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): { [key in V]: K } {
const result = {} as { [key in V]: K };

for (const key of Object.keys(obj)) {
const value = obj[key as K] as V;
result[value] = key as K;
const keys = Object.keys(obj) as K[];
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const value = obj[key];
result[value] = key;
}

return result;
Expand Down

0 comments on commit 72a21e1

Please sign in to comment.