capacity of a hard drive and its measure
unit, return its capacity in bytes.
Here are all possible measure units and their sizes:
|Kilobyte (KB)||1,024 bytes|
|Megabytes (MB)||1,048,576 bytes|
|Gigabyte (G)||1,073,741,824 bytes|
|Terabyte (TB)||1,099,511,627,776 bytes|
|Petabyte (P)||1,125,899,906,842,624 bytes|
capacity = 12 and
unit = "KB", the output should be
`ComputerUnitsToByte(capacity, unit) = "12288".
12 * 1024 = 12288, which is the answer.
- [time limit] 4000ms (php)
[input] integer capacity
1 ≤ capacity ≤ 100.
[input] string unit
Unit symbol, one of the following strings:
The answer as a string. It is guaranteed to be smaller than
ComputerUnitsToByte = (c, u) => c * Math.pow(1024, 1 + "KMGTP".indexOf(u)) + ""