Skip to content

Commit

Permalink
util: use average bias while grouping arrays
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
BridgeAR authored and targos committed Jun 18, 2019
1 parent 7e61760 commit b6f113b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,8 @@ function groupArrayElements(ctx, output, value) {
(totalLength / actualMax > 5 || maxLength <= 6)) {

const approxCharHeights = 2.5;
const biasedMax = Math.max(actualMax - 4, 1);
const averageBias = Math.sqrt(actualMax - totalLength / output.length);
const biasedMax = Math.max(actualMax - 3 - averageBias, 1);
// Dynamically check how many columns seem possible.
const columns = Math.min(
// Ideally a square should be drawn. We expect a character to be about 2.5
Expand Down
14 changes: 6 additions & 8 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2252,14 +2252,12 @@ assert.strictEqual(

expected = [
'[',
' 1, 1, 1,',
' 1, 1, 1,',
' 1, 1, 1,',
' 1, 1, 1,',
' 1, 1, 1,',
' 1, 1, 1,',
' 1, 1, 1,',
' 1, 1, 1,',
' 1, 1, 1, 1,',
' 1, 1, 1, 1,',
' 1, 1, 1, 1,',
' 1, 1, 1, 1,',
' 1, 1, 1, 1,',
' 1, 1, 1, 1,',
' 1, 1, 123456789',
']'
].join('\n');
Expand Down

0 comments on commit b6f113b

Please sign in to comment.