Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let vaucherValue = Number(input[0]);
- let prize = 0;
- let tickets = 0;
- let others = 0;
- for (let i = 1; i < input.length; i++) {
- if (input[i] !== 'End') {
- if (input[i].length > 8) {
- prize = input[i].charCodeAt(0) + input[i].charCodeAt(1);
- if (prize < vaucherValue) {
- vaucherValue = vaucherValue - prize;
- tickets += 1;
- }
- } else if (input[i].length <= 8) {
- prize = input[i].charCodeAt(0);
- if (prize < vaucherValue) {
- vaucherValue = vaucherValue - prize;
- others += 1;
- }
- }
- } else {
- break;
- }
- }
- console.log(tickets);
- console.log(others);
- }
- solve([
- '1500',
- 'Avengers: Endgame',
- 'Bohemian Rhapsody',
- 'Deadpool 2',
- 'Pepsi',
- 'End'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement