nikolayneykov

Untitled

Nov 3rd, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const getGets = (arr) => {
  2.   let index = 0;
  3.  
  4.   return () => {
  5.     const toReturn = arr[index];
  6.     index += 1;
  7.     return toReturn;
  8.   };
  9. };
  10. // this is the test
  11. const test = ['1.92', '5'];
  12.  
  13. const gets = this.gets || getGets(test);
  14. const print = this.print || console.log;
  15.  
  16. let price = +gets();
  17. let paid = +gets();
  18. let change = (paid - price) * 100;
  19.  
  20. if (change > 100) {
  21.   const levCount = ~~(change / 100);
  22.   change -= levCount * 100;
  23.   print(`${levCount} x 1 lev`);
  24. }
  25.  
  26. if (change > 50) {
  27.   change -= 50;
  28.   print(`1 x 50 stotinki`);
  29. }
  30.  
  31. if (change > 20) {
  32.   const stotinkiCount = ~~(change / 20);
  33.   change -= 20 * stotinkiCount;
  34.   print(`${stotinkiCount} x 20 stotinki`);
  35. }
  36.  
  37. if (change > 10) {
  38.   change -= 10;
  39.   print(`1 x 10 stotinki`);
  40. }
  41.  
  42. if (change > 5) {
  43.   change -= 5;
  44.   print(`1 x 5 stotinki`);
  45. }
  46.  
  47. if (change > 2) {
  48.   const stotinkiCount = ~~(change / 2);
  49.   change -= 2 * stotinkiCount;
  50.   print(`${stotinkiCount} x 2 stotinki`);
  51. }
  52.  
  53. if (change === 1) {
  54.   print(`1 x 1 stotinka`);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment