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: nodejs#28070
Refs: nodejs#27690
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR committed Jun 17, 2019
1 parent 87a22cf commit b97b003
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 @@ -997,7 +997,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 @@ -2274,14 +2274,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 b97b003

Please sign in to comment.