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)) {
|
(totalLength / actualMax > 5 || maxLength <= 6)) {
|
||||||
|
|
||||||
const approxCharHeights = 2.5;
|
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.
|
// Dynamically check how many columns seem possible.
|
||||||
const columns = Math.min(
|
const columns = Math.min(
|
||||||
// Ideally a square should be drawn. We expect a character to be about 2.5
|
// Ideally a square should be drawn. We expect a character to be about 2.5
|
||||||
|
@ -2274,14 +2274,12 @@ assert.strictEqual(
|
|||||||
|
|
||||||
expected = [
|
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',
|
' 1, 1, 123456789',
|
||||||
']'
|
']'
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user