Advertisement
sivancheva

Kompot

Sep 11th, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. function kompot(arr) {
  2. let peachKg = 0;
  3. let plumKg = 0;
  4. let cherryKg = 0;
  5. let fruitsForRakia = 0;
  6.  
  7. for (let line of arr) {
  8.  
  9. let [fruit, kg] = line.split(" ").map(x => x.trim());
  10. switch (fruit.toLowerCase()) {
  11. case "peach":
  12. peachKg += +kg;
  13. break;
  14. case "plum":
  15. plumKg += +kg;
  16. break;
  17. case "cherry":
  18. cherryKg += +kg;
  19. break;
  20. default:
  21. fruitsForRakia += +kg;
  22. break;
  23. }
  24. }
  25. let cherryCompots = Math.floor((cherryKg*1000/9)/25);
  26. let peachCompot = Math.floor((peachKg*1000/140)/2.5);
  27. let plumCompots = Math.floor((plumKg*1000/20)/10);
  28. let rakiqLtr = (fruitsForRakia*0.2);
  29. console.log(`Cherry kompots: ${cherryCompots}\nPeach kompots: ${peachCompot}\nPlum kompots: ${plumCompots}\nRakiya liters: ${rakiqLtr.toFixed(2)}`);
  30. }
  31.  
  32. kompot(['cherry 1.2',
  33. 'peach 2.2',
  34. 'plum 5.2',
  35. 'peach 0.1',
  36. 'cherry 0.2',
  37. 'cherry 5.0',
  38. 'plum 10',
  39. 'cherry 20.0',
  40. 'papaya 20']
  41. );
  42.  
  43. Problem 1 – Kompot
  44.  
  45. It`s a summer. You can find fruits all around you. Mitko likes kompots very much, specially peaches, cherries and plums kompots and he wants to make some for the winter.
  46. You may receive the following fruits:
  47. - Peach {0.200}
  48. - Plum {0.120}
  49. - Cherry {2.5}
  50. The number in the bracket is fruit weight in kilograms. You have to make kompots from this fruits as you know that 1 peach weight is 140 g, 1 plum weight is 20 g and 1 cherry weight is 9 g.
  51. In the same time you know that for 1 kompot you must use the following numbers of fruits:
  52. - 2.5 peach
  53. - 10 plum
  54. - 25 cherry
  55. After you make your kompots round them floor.
  56. If you receive other kind of fruits collect them in a bucket. You will make rakiya from them. You will add some sugar and you will produce 0.200 l (liter) rakiya from 1 kilo fruit.
  57. Input
  58. You will receive an array of strings. In the first input element, you will receive all kind of fruits and in the second input element you will receive the weight in kilograms.
  59. Output
  60. • The output will be like the examples below. Rakiya must be formatted to the second number after the coma
  61. Constraints
  62. • The input will always be valid.
  63. • The input will be a string containing only letters, numbers, spaces and comas.
  64. • Allowed working time / memory: 100ms / 16MB.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement