Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(array) {
- let list = array.shift().split(' ')
- for (let i = 0; i < array.length; i++) {
- let element = array[i].split(' ')
- let command = element[0]
- let present = element[1]
- if (command === 'No Money'){
- break;
- }
- if (command === 'OutOfStock') {
- let count = list.filter(item => item === present).length;
- for (let i = 0; i < count; i++) {
- let index = list.indexOf(present)
- let none = 'None'
- list.splice(index, 1, none)
- }
- } else if (command === 'Required') {
- let index = element[2]
- if (index >= 0 && index <= list.length-1) {
- list.splice(index, 1, present)
- }
- } else if (command === 'JustInCase') {
- list.splice(list.length - 1, 1, present)
- }
- }
- let filtred = list.filter(item => item !== 'None')
- console.log(filtred.join(' '))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement