mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
util: use average bias while grouping arrays
This makes sure that strongly deviating entry length are taken into account while grouping arrays. PR-URL: https://github.com/nodejs/node/pull/28070 Refs: https://github.com/nodejs/node/issues/27690 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
87a22cff77
commit
b97b003c35
@ -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
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user