Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pipesInPool(input) {
- let volume = Number(input.shift());
- let p1 = Number(input.shift());
- let p2 = Number(input.shift());
- let hours = Number(input.shift());
- let volumeTotal = Math.floor(p1 * hours + p2 * hours);
- if (volumeTotal <= volume) {
- let poolVolume = Math.abs((volumeTotal / volume) * 100);
- let p1Percent = Math.abs(((p1 * hours) / volumeTotal) * 100);
- let p2Percent = Math.abs(((p2 * hours) / volumeTotal) * 100);
- console.log(
- `The pool is ${poolVolume.toFixed(2)}% full. Pipe 1: ${p1Percent.toFixed(
- 2
- )}%. Pipe 2: ${p2Percent.toFixed(2)}%.`
- );
- } else if (volumeTotal > volume) {
- console.log(
- `For ${hours} hours the pool overflows with ${Math.abs(
- volume - volumeTotal
- ).toFixed(2)} liters.`
- );
- }
- }
- pipesInPool(["1000", "100", "120", "3"]);
- pipesInPool(["100", "100", "100", "2.5"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement