Advertisement
desito07

pipesInPool

Apr 1st, 2020
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. function pipesInPool(input) {
  2. let volume = Number(input.shift());
  3. let p1 = Number(input.shift());
  4. let p2 = Number(input.shift());
  5. let hours = Number(input.shift());
  6.  
  7. let volumeTotal = Math.floor(p1 * hours + p2 * hours);
  8.  
  9. if (volumeTotal <= volume) {
  10. let poolVolume = Math.abs((volumeTotal / volume) * 100);
  11. let p1Percent = Math.abs(((p1 * hours) / volumeTotal) * 100);
  12. let p2Percent = Math.abs(((p2 * hours) / volumeTotal) * 100);
  13. console.log(
  14. `The pool is ${poolVolume.toFixed(2)}% full. Pipe 1: ${p1Percent.toFixed(
  15. 2
  16. )}%. Pipe 2: ${p2Percent.toFixed(2)}%.`
  17. );
  18. } else if (volumeTotal > volume) {
  19. console.log(
  20. `For ${hours} hours the pool overflows with ${Math.abs(
  21. volume - volumeTotal
  22. ).toFixed(2)} liters.`
  23. );
  24. }
  25. }
  26. pipesInPool(["1000", "100", "120", "3"]);
  27. pipesInPool(["100", "100", "100", "2.5"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement