Advertisement
Guest User

Untitled

a guest
Feb 7th, 2021
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. function patients(input) {
  2. let index = 0;
  3. let n = Number(input[index++]);
  4. let num = Number(input[index++]);
  5. let doctors = 7;
  6. let sumTreatedPatients = 0;
  7. let sumUntreatedPatient = 0;
  8.  
  9. let currentTreatedPatients = 0;
  10. let currentUntreatedPatients = 0;
  11.  
  12. for (let i = 1; i <= n; i++) {
  13.  
  14. if (i % 3 === 0) {
  15. if (sumUntreatedPatient > sumTreatedPatients) {
  16. doctors++;
  17. }
  18. }
  19.  
  20. if (num >= doctors) {
  21. currentTreatedPatients = doctors;
  22. } else {
  23. currentTreatedPatients = num;
  24. }
  25.  
  26. currentUntreatedPatients = num - doctors;
  27.  
  28. if (currentUntreatedPatients <= 0) {
  29. currentUntreatedPatients = 0;
  30. }
  31.  
  32. sumTreatedPatients += currentTreatedPatients;
  33. sumUntreatedPatient += currentUntreatedPatients;
  34.  
  35. num = Number(input[index++]);
  36. }
  37. console.log(`Treated patients: ${sumTreatedPatients}.`);
  38. console.log(`Untreated patients: ${sumUntreatedPatient}.`);
  39. }
  40.  
  41. patients(["6", "25", "25", "25", "25", "25", "2"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement