Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 225fb1b

Browse filesBrowse files
committed
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 <jasnell@gmail.com>
1 parent 8f4bb19 commit 225fb1b
Copy full SHA for 225fb1b

File tree

Expand file treeCollapse file tree

2 files changed

+8
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+8
-9
lines changed
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+2-1Lines changed: 2 additions & 1 deletion
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
Collapse file

‎test/parallel/test-util-inspect.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js
+6-8Lines changed: 6 additions & 8 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.