Guest User

Untitled

a guest
Jun 4th, 2020
106
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let voucherValue = Number(input.shift());
  3.   let tickets = 0;
  4.   let other = 0;
  5.  
  6.   let next = input.shift();
  7.   while (next !== 'End') {
  8.     let price = 0;
  9.     if (next.length > 8) {
  10.       price = next.charCodeAt(0) + next.charCodeAt(1);
  11.     } else {
  12.       price = next.charCodeAt(0);
  13.     }
  14.  
  15.     if (price > voucherValue) {
  16.       break;
  17.     }
  18.  
  19.     voucherValue -= price;
  20.     if (next.length > 8) {
  21.       tickets++;
  22.     } else {
  23.       other++;
  24.     }
  25.  
  26.     next = input.shift();
  27.   }
  28.  
  29.   console.log(tickets);
  30.   console.log(other);
  31. }
RAW Paste Data