Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calculate(capacity, passengersArr){
- let outputArr = [];
- let startWagon = 0;
- for (const wagon of passengersArr) {
- if (startWagon + wagon > capacity){
- startWagon += wagon - capacity
- outputArr.push(capacity)
- } else{
- outputArr.push(wagon + startWagon);
- startWagon = 0;
- }
- }
- console.log(outputArr)
- if(startWagon <= 0){
- console.log(`All passengers aboard`)
- } else {
- console.log(`Could not fit ${startWagon} passengers`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement