MartinPK 0 Точки

## Mid exam 02.Array Modifier

Mоже ли някой да ми помогне с задачата от миналият mid exam 02.Array Modifier,решавам я изкарва ми вярно примерните входове но джъдж ми казва 70/100.https://pastebin.com/qbU5CB9P

ето и задачата ->https://judge.softuni.org/Contests/Practice/Index/2474#1

``````function arrayCommands(array){
let index = 0
let numbers = String(array[0]).split(' ')
let arrayOfCommands = []
let command = ''
let sumForMultiplier = 0
let decreasedArray = []

index++
while(command != 'end'){
command = array[index].split(' ')
arrayOfCommands.push(array[index])
let firstCommand = command[0]

if(firstCommand === 'swap'){
let temp = numbers[command[1]]
numbers[command[1]] = numbers[command[2]]
numbers[command[2]] = temp

}else if(firstCommand === 'multiply'){
sumForMultiplier = Number(numbers[command[1]]) * Number(numbers[command[2]])
numbers[command[1]] = sumForMultiplier

}else if(firstCommand === 'decrease'){
for(let i = 0;i < numbers.length;i++){
decreasedArray.push(numbers[i] - 1)

}
}

index++

}
if(decresedArray === undefined || decresaedArray.length == 0) {
console.log(numbers.join(', '))
}else{
console.log(decreasedArray.join(', '));
}

}
arrayCommands([
'23 -2 321 87 42 90 -123',
'swap 1 3',
'swap 3 6',
'swap 1 0',
'multiply 1 2',
'multiply 2 1',
'decrease',
'end',
]
)``````

Тагове:
0
03/02/2022 11:54:21