6 kyu

Converter

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

Stats:

CreatedJul 19, 2017
PublishedJul 21, 2017
Warriors Trained592
Total Skips14
Total Code Submissions2341
Total Times Completed153
JavaScript Completions153
Total Stars20
% of votes with a positive feedback rating93% of 50
Total "Very Satisfied" Votes44
Total "Somewhat Satisfied" Votes5
Total "Not Satisfied" Votes1
Total Rank Assessments10
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Mishaboo Avatar
  • smile67 Avatar
  • dfhwze Avatar
Ad