

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Problem Can we fit remaining passengers in the bus using JavaScript
Problem
We are required to write a JavaScript function that takes in three parameters −
cap − is the amount of people the bus can hold excluding the driver.
on − is the number of people on the bus excluding the driver.
wait − is the number of people waiting to get on to the bus excluding the driver.
If there is enough space, we should return 0, and if there isn't, we should return the number of passengers we can't take.
Example
Following is the code −
const cap = 120; const on = 80; const wait = 65; const findCapacity = (cap, on, wait) => { let x = 0; let y = (on + wait); if(y > cap){ x += (y - cap); }; if(x < 0){ x = 0; }; return x; }; console.log(findCapacity(cap, on, wait));
Output
25
- Related Questions & Answers
- CAN Bus with Arduino
- How can we approach the problem of clustering with obstacles?
- Combination sum problem using JavaScript
- How can we debug JavaScript using Firefox?
- How can we debug JavaScript using Google Chrome?
- How can Tensorflow be used to fit the data to the model using Python?
- How can Tensorflow be used to compile and fit the model using Python?
- Finding sum of remaining numbers to reach target average using JavaScript
- The algorithm problem - Backtracing pattern in JavaScript
- Program to find maximum number of boxes we can fit inside another boxes in python
- Remove number from array and shift the remaining ones JavaScript
- How can we separate the special characters in JavaScript?
- Snail Trail Problem in JavaScript
- Recursive Staircase problem in JavaScript
- Distributing Bananas Problem in JavaScript
Advertisements