Count value frequencies and render a vertical bar histogram

You are given an array of numbers. Your task is to write a function buildHistogram() that generates a histogram based on the occurrences of each unique number in the array. The histogram should visually represent the frequency of each number with vertical bars, displaying the count on the left axis. This histogram in JavaScript counts how often each value appears, just like a statistical histogram.
This challenge involves:
Example:
Input: [2, 4, 5, 2, 3, 4]
Histogram:
4 | ##
3 | ####
2 | ######
1 | ########
---------
2 3 4 5
Your implementation should dynamically generate the histogram based on the input array, accommodating arrays with varying lengths and ranges of numbers. Consider the visualization aspect of the histogram, ensuring that the bars are proportional and accurately reflect the data’s distribution.