Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function train(input) {
- let arr = input.shift().split(' ').map(Number);
- let capacity = Number(input.shift());
- while (input.length !== 0) {
- let command = input.shift().split(' ');
- command[0] === 'Add' ? arr.push(Number(command[1])) : command = Number(command[0]);
- for (let i = 0; i < arr.length; i++) {
- if (arr[i] + command <= capacity) {
- arr[i] += command;
- break;
- }
- }
- }
- console.log(arr.join(' '));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement