Skip to content

Commit b6f113b

Browse files
BridgeARtargos
authored andcommitted
util: use average bias while grouping arrays
This makes sure that strongly deviating entry length are taken into account while grouping arrays. PR-URL: #28070 Refs: #27690 Reviewed-By: James M Snell <[email protected]>
1 parent 7e61760 commit b6f113b

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lib/internal/util/inspect.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,8 @@ function groupArrayElements(ctx, output, value) {
972972
(totalLength / actualMax > 5 || maxLength <= 6)) {
973973

974974
const approxCharHeights = 2.5;
975-
const biasedMax = Math.max(actualMax - 4, 1);
975+
const averageBias = Math.sqrt(actualMax - totalLength / output.length);
976+
const biasedMax = Math.max(actualMax - 3 - averageBias, 1);
976977
// Dynamically check how many columns seem possible.
977978
const columns = Math.min(
978979
// Ideally a square should be drawn. We expect a character to be about 2.5

test/parallel/test-util-inspect.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -2252,14 +2252,12 @@ assert.strictEqual(
22522252

22532253
expected = [
22542254
'[',
2255-
' 1, 1, 1,',
2256-
' 1, 1, 1,',
2257-
' 1, 1, 1,',
2258-
' 1, 1, 1,',
2259-
' 1, 1, 1,',
2260-
' 1, 1, 1,',
2261-
' 1, 1, 1,',
2262-
' 1, 1, 1,',
2255+
' 1, 1, 1, 1,',
2256+
' 1, 1, 1, 1,',
2257+
' 1, 1, 1, 1,',
2258+
' 1, 1, 1, 1,',
2259+
' 1, 1, 1, 1,',
2260+
' 1, 1, 1, 1,',
22632261
' 1, 1, 123456789',
22642262
']'
22652263
].join('\n');

0 commit comments

Comments
 (0)