6 kyu
Converter
153Mishaboo
Description:
Your friend have an issue with converting file sizes between B, KB, MB, GB and TB. Could you create converter that will help him?
Create class Converter
that will have:
Properties:
- number that represent size amount (not necessarily integer).
- string that represent current unit type. Unit type can be only one of the next:
'B', 'KB', 'MB', 'GB', 'TB'
Methods:
unit
: return current unit type;size
: return current size and unit as a string'19 MB'
or'38.45 GB'
or'7.5 TB'
toB
: convert size to Bytes and unit to'B'
toKB
: convert size to Kilobytes and unit to'KB'
toMB
: convert size to Megabyte and unit to'MB'
toGB
: convert size to Gigabyte and unit to'GB'
toTB
: convert size to Terabyte and unit to'TB'
Note, that there can be maximum 3 digits after decimal and a number should be rounded to lower digit (floor)
Example:
var file = new Converter(1, "TB");
file.toMB();
file.unit; // 'MB'
file.size; // '1048576 MB'
Algorithms
Similar Kata:
Stats:
Created | Jul 19, 2017 |
Published | Jul 21, 2017 |
Warriors Trained | 592 |
Total Skips | 14 |
Total Code Submissions | 2341 |
Total Times Completed | 153 |
JavaScript Completions | 153 |
Total Stars | 20 |
% of votes with a positive feedback rating | 93% of 50 |
Total "Very Satisfied" Votes | 44 |
Total "Somewhat Satisfied" Votes | 5 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 10 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |