0
0
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:
Ruben Bridgewater 2019-06-05 14:57:46 +02:00
parent 87a22cff77
commit b97b003c35
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 8 additions and 9 deletions

View File

@ -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

View File

@ -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');