Skip to content

Commit c95c5d9

Browse files
committed
chore: only filter out boolean keys
1 parent 304c4f8 commit c95c5d9

File tree

2 files changed

+6
-26
lines changed

2 files changed

+6
-26
lines changed

.scripts/compare-database.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,20 +243,12 @@ export const getValueComplexity = (value) => {
243243
};
244244

245245
export const buildSortByKeys = (keys) => (a, b) => {
246-
// Sort keys based on value complexity and then find the first differing key
247-
const sortedKeys = keys.slice().sort((keyA, keyB) => {
248-
const complexityA = Math.max(getValueComplexity(a[keyA]), getValueComplexity(b[keyA]));
249-
const complexityB = Math.max(getValueComplexity(a[keyB]), getValueComplexity(b[keyB]));
250-
251-
// Sort by complexity descending (more complex first), then by key name ascending
252-
if (complexityA !== complexityB) {
253-
return complexityB - complexityA;
254-
}
255-
return keyA.localeCompare(keyB);
256-
});
246+
// Filter out keys where either value is boolean, then use original strategy
247+
const filteredKeys = keys.filter((key) =>
248+
typeof a[key] !== 'boolean' && typeof b[key] !== 'boolean'
249+
);
257250

258-
// Use deep comparison instead of reference comparison for objects
259-
const found = sortedKeys.find((key) => {
251+
const found = filteredKeys.find((key) => {
260252
const comparison = autoCompare(a[key], b[key]);
261253
return comparison !== 0;
262254
});

.scripts/compare-database.test.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import assert from 'node:assert';
11-
import { autoCompare, buildSortByKeys, getValueComplexity } from './compare-database.js';
11+
import { autoCompare, buildSortByKeys } from './compare-database.js';
1212

1313
// Test helper function
1414
const runTest = (testName, testFn) => {
@@ -201,18 +201,6 @@ runTest('autoCompare - buildSortByKeys integration for database data', () => {
201201
assert.strictEqual(comparison, 0); // Should be identical
202202
});
203203

204-
// Test cases for getValueComplexity function
205-
runTest('getValueComplexity - returns correct complexity scores', () => {
206-
assert.strictEqual(getValueComplexity(null), 0);
207-
assert.strictEqual(getValueComplexity(undefined), 0);
208-
assert.strictEqual(getValueComplexity(true), 1);
209-
assert.strictEqual(getValueComplexity(false), 1);
210-
assert.strictEqual(getValueComplexity(42), 2);
211-
assert.strictEqual(getValueComplexity('string'), 3);
212-
assert.strictEqual(getValueComplexity([1, 2, 3]), 4);
213-
assert.strictEqual(getValueComplexity({ key: 'value' }), 5);
214-
});
215-
216204
// Test cases for buildSortByKeys with complexity sorting
217205
runTest('buildSortByKeys - prioritizes complex values', () => {
218206
const obj1 = {

0 commit comments

Comments
 (0)