Skip to content

Commit b97b003

Browse files
committedJun 17, 2019
util: use average bias while grouping arrays
This makes sure that strongly deviating entry length are taken into account while grouping arrays. PR-URL: nodejs#28070 Refs: nodejs#27690 Reviewed-By: James M Snell <[email protected]>
1 parent 87a22cf commit b97b003

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
@@ -997,7 +997,8 @@ function groupArrayElements(ctx, output, value) {
997997
(totalLength / actualMax > 5 || maxLength <= 6)) {
998998

999999
const approxCharHeights = 2.5;
1000-
const biasedMax = Math.max(actualMax - 4, 1);
1000+
const averageBias = Math.sqrt(actualMax - totalLength / output.length);
1001+
const biasedMax = Math.max(actualMax - 3 - averageBias, 1);
10011002
// Dynamically check how many columns seem possible.
10021003
const columns = Math.min(
10031004
// 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
@@ -2274,14 +2274,12 @@ assert.strictEqual(
22742274

22752275
expected = [
22762276
'[',
2277-
' 1, 1, 1,',
2278-
' 1, 1, 1,',
2279-
' 1, 1, 1,',
2280-
' 1, 1, 1,',
2281-
' 1, 1, 1,',
2282-
' 1, 1, 1,',
2283-
' 1, 1, 1,',
2284-
' 1, 1, 1,',
2277+
' 1, 1, 1, 1,',
2278+
' 1, 1, 1, 1,',
2279+
' 1, 1, 1, 1,',
2280+
' 1, 1, 1, 1,',
2281+
' 1, 1, 1, 1,',
2282+
' 1, 1, 1, 1,',
22852283
' 1, 1, 123456789',
22862284
']'
22872285
].join('\n');

0 commit comments

Comments
 (0)
Please sign in to comment.