-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathprogressBar.js
30 lines (22 loc) · 1 KB
/
progressBar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* @author 5antos#4876
* @param {number} current Current progress of the bar
* @param {number} total The value of the progress when the bar is totally filled
* @param {number} barSize Fixed bar size
* @returns {string} Progress bar
*/
function progressBar(current, total, barSize) {
const progress = Math.round((barSize*current)/total)
return '▮'.repeat(progress) + '▯'.repeat(barSize-progress)
}
function progressBarEnhanced(current, total, barSize) {
const progress = Math.round((barSize*current)/total)
return '—'.repeat(progress > 0 ? progress-1 : progress) + '•' + '-'.repeat(barSize-progress)
}
// Example Outputs:
progressBar(50, 100, 10) // ▮▮▮▮▮▯▯▯▯▯
progressBar(100, 1000, 10) // ▮▯▯▯▯▯▯▯▯▯
progressBar(20, 20, 5) // ▮▮▮▮▮
progressBarEnhanced(50, 100, 10) // ————•-----
progressBarEnhanced(100, 1000, 10) // •---------
progressBarEnhanced(20, 20, 5) // ————•