Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - //02. Pipes In Pool.js
 - function pipesInPool(arr) {
 - 'use strict'
 - let input = arr[0].split('\n')
 - let volumeLitres = Number(input[0])
 - let p1LitresPerHour = Number(input[1])
 - let p2LitresPerHour = Number(input[2])
 - let hNoWorker = Number(input[3])
 - let waterLitres = (p1LitresPerHour * hNoWorker) + (p2LitresPerHour * hNoWorker)
 - if (waterLitres <= volumeLitres) {
 - let percent = Math.trunc(waterLitres / volumeLitres * 100)
 - let percent1 = Math.trunc(p1LitresPerHour * hNoWorker / waterLitres * 100)
 - let percent2 = Math.trunc(p2LitresPerHour * hNoWorker / waterLitres * 100)
 - console.log(`The pool is ${percent}% full. Pipe 1: ${percent1}%. Pipe 2: ${percent2}%.`)
 - } else {
 - console.log(`For ${hNoWorker} hours the pool overflows with ${waterLitres - volumeLitres} liters.`)
 - }
 - }
 - pipesInPool(['1000\n100\n120\n3'])
 - pipesInPool(['100\n100\n100\n2.5'])
 - function pipesInPool0(arr) {
 - let input = arr[0].split('\n')
 - let volume = parseInt(input[0])
 - let pipe1 = parseInt(input[1])
 - let pipe2 = parseInt(input[2])
 - let hours = +input[3]
 - let water = (pipe1 + pipe2) * hours;
 - if (water <= volume) {
 - console.log(
 - `The pool is ${~~((water / volume) * 100.0)}% full. Pipe 1: ${~~((pipe1 * hours) / water * 100.0)}%. Pipe 2: ${~~(((pipe2 * hours) / water) * 100.0)}%.`);
 - }
 - else {
 - console.log(
 - `For ${hours} hours the pool overflows with ${water - volume} liters.`);
 - }
 - }
 - function pipesInPool2(arr) {
 - let input = arr[0].split('\n')
 - let volume = Number(input[0])
 - let p1 = Number(input[1])
 - let p2 = Number(input[2])
 - let hours = Number(input[3])
 - let pipe1 = p1 * hours;
 - let pipe2 = p2 * hours;
 - let pipePool = pipe1 + pipe2;
 - if (pipePool <= volume) {
 - let poolPercent = (pipePool / volume) * 100;
 - let p1Percent = (pipe1 / pipePool) * 100;
 - let p2Percent = (pipe2 / pipePool) * 100;
 - console.log(`The pool is ${Math.trunc(poolPercent)}% full. Pipe 1: ${Math.trunc(p1Percent)}%. Pipe 2: ${Math.trunc(p2Percent)}%.`);
 - } else if (pipePool > volume) {
 - let overFlow = pipePool - volume;
 - console.log(`For ${hours} hours the pool overflows with ${overFlow} liters.`);
 - }
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment