3

Consider the following stack snippet:

// A Tree(a) is one of:
// - null
// - tree(a, Tree(a), Tree(a))
const tree = (value, left, right) => ({ value, left, right });    

const buildTree = (xs, i = 0) => i >= xs.length ? null :
    tree(xs[i], buildTree(xs, 2 * i + 1), buildTree(xs, 2 * i + 2));

console.log(buildTree([1, 10, 100, 20, 2, 3, 30, 300, 40, 4]));

As you can see, there's some space above the console when you run the snippet. If you maximize the output window, then this problem is even more noticeable. This problem can be fixed as follows:

// A Tree(a) is one of:
// - null
// - tree(a, Tree(a), Tree(a))
const tree = (value, left, right) => ({ value, left, right });    

const buildTree = (xs, i = 0) => i >= xs.length ? null :
    tree(xs[i], buildTree(xs, 2 * i + 1), buildTree(xs, 2 * i + 2));

console.log(buildTree([1, 10, 100, 20, 2, 3, 30, 300, 40, 4]));
.as-console-wrapper { max-height: 100% !important; top: 0; }

However, the CSS code is not a part of the answer, and hence it shouldn't be seen by others. Instead, we should be able to configure the console height in the configuration options of the snippet. For example:

<!-- begin snippet: js console-max: true -->

This feature will be helpful for JavaScript-only snippets which display their output only via the console. Other snippets can continue using console: true for displaying HTML and for backward compatibility.

You must log in to answer this question.

Browse other questions tagged .