Place items in the shortest column for a masonry layout

Create a dynamic Masonry layout using Vanilla JavaScript, which organizes a series of items into a grid layout that optimizes space by fitting elements in the optimal position based on available vertical space. This layout should resemble the way stones are laid in a masonry wall, where each item is placed in the shortest column available at the time of placement, creating a staggered effect rather than a uniform grid. CSS multi-column layout is one common way to build a masonry grid.
Your task is to implement a function that positions each item within a container to achieve the Masonry layout effect. Each item has its own content and height, and the layout should consist of a specified number of columns with a fixed gap between items. The items should be arranged such that they fill up the shortest column available, ensuring that the layout is balanced and the overall height of the grid is minimized.
The implementation should include the following:
Example:
const items = [
{ content: 'Item 1', height: 150 },
{ content: 'Item 2', height: 100 },
{ content: 'Item 3', height: 120 },
// more items...
];
// Expected to create a Masonry layout with the given items inside a container with an id of 'masonry'.
This task assesses your ability to manipulate the DOM using Vanilla JavaScript, handle dynamic layout calculations, and apply creative problem-solving to achieve complex layout patterns without external libraries.