## Помощ със задача 05. Tseam Account от Arrays - More Exercise JS-Fundamentals

Здравейте,

от сума ти време се мъча с 'Expansion' от Tseam Account - заради него ми дава 50-100. Ще съм благодарна, ако някой помогне.

https://judge.softuni.org/Contests/Practice/Index/1272#4

ето и решението:

function solve(strings) {

let newArr = strings.shift().split(' ')

for (let i = 0; i < strings.length; i++) {
let [command, game] = strings[i].split(' ')
let index = newArr.indexOf(game)

if (command === 'Install') {
if(index < 0)
newArr.push(game)
} else if (command === 'Uninstall') {
if(index > 0 && index < newArr.length){
newArr.splice(index, 1)
}
} else if (command === 'Update') {
if(index > 0 && index < newArr.length){
newArr.splice(index, 1)
newArr.push(game)
}
} else if (command === 'Expansion') {
let [newGame, expansion] = game.split('-')
if(index > 0 && index < newArr.length){
newArr.splice(index + 1, 0, `\${newGame}:\${expansion}`)
}
} else if (command === 'Play!') {
console.log(newArr.join(' '));
break;
}
}
}

Тагове:
0

Много Ви благодаря :)

Извинете ако Ви досаждам(нямам други въпроси :))) ), но можете ли да ми кажете защо  "Expansion" не работи тук :

function solve(strings) {

let newArr = strings.shift().split(' ')

for (let i = 0; i < strings.length; i++) {
let [command, game] = strings[i].split(' ')

if (command === 'Install') {
if (!newArr.includes(game)) {
newArr.push(game)
}
} else if (command === 'Uninstall') {
if (newArr.includes(game)) {
if(newArr.indexOf(game) !== undefined){
newArr.splice(game, 1)
}
}
} else if (command === 'Update') {
if (newArr.includes(game)) {
if(newArr.indexOf(game) !== undefined){
newArr.splice(game, 1)
newArr.push(game)
}
}
} else if (command === 'Expansion') {
let [newGame, expansion] = game.split('-')
index = newArr.indexOf(newGame)
if (newArr.includes(newGame)) {
if(newArr.indexOf(newGame) !== undefined){
newArr.splice(newGame + 1, 0, `\${newGame}:\${expansion}`)
}
}
} else if (command === 'Play!') {
console.log(newArr.join(' '));
break;
}
}
}

0
13/02/2023 15:56:15
Axiomatik 2422 Точки

``````Return value indexOf() =>

The index of the first occurrence of searchString found, or -1 if not found.``````

``````"Blue Whale".indexOf("Blue"); // returns  0
"Blue Whale".indexOf("Blute"); // returns -1
"Blue Whale".indexOf("Whale", 0); // returns  5
"Blue Whale".indexOf("Whale", 5); // returns  5
"Blue Whale".indexOf("Whale", 7); // returns -1
"Blue Whale".indexOf(""); // returns  0
"Blue Whale".indexOf("", 9); // returns  9
"Blue Whale".indexOf("", 10); // returns 10
"Blue Whale".indexOf("", 11); // returns 10
``````

1