JavaScript: Horizontal histogram

Last update: 01 Sep 23:20
0
Students

Dice is a six-sided die that is thrown several times. A histogram is a graphical representation of data using columns.

histogram.js

Implement and export as default a function that displays a horizontal histogram. The function takes as input the number of dice rolls and a function that simulates the dice roll (already implemented). The output of this function is a number between 1 and 6 that represents one of the six faces of the dice.

The dice faces and the number of their rolls are represented by rows in the histogram. The results are displayed graphically (using the # characters) and as a numeric value, except when the number is 0 (zero).

Examples

import play from '../histogram.js';

play(100, rollDie);
// => 1|####################### 23
//    2|################## 18
//    3|############# 13
//    4|#################### 20
//    5|############ 12
//    6|############## 14

play(13, rollDie);
// => 1|
//    2|## 2
//    3|# 1
//    4|## 2
//    5|#### 4
//    6|#### 4

Tips

  • Histogram
  • Use the functions from the lodash library to solve the task

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests