Skip to content

feat: speed up objects loops #5

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export default function diff(
newObj: Record<string, any> | any[]
): Difference[] {
let diffs: Difference[] = [];
for (const key in obj) {
const keys = Object.keys(obj);
for(let i = 0; i < keys.length; i++) {
const key = keys[i];
if (!(key in newObj)) {
diffs.push({
type: "REMOVE",
Expand Down Expand Up @@ -45,7 +47,9 @@ export default function diff(
});
}
}
for (const key in newObj) {
const nkeys = Object.keys(newObj);
for(let i = 0; i < nkeys.length; i++) {
const key = nkeys[i];
if (!(key in obj)) {
diffs.push({
type: "CREATE",
Expand Down