Programming Fundamentals Mid Exam - 22 October 2023 - задача 02. Friend List Maintenance
Здравейте,
Тази задача ми дава 90/100 и не мога да намеря къде е проблема може ли малко помощ?
function friendList(input) {
const friends = input[0].split(', ');
const originalNames = [...friends]; // Keep a copy of original names
const blacklist = new Set();
const lost = new Set();
for (let i = 1; i < input.length; i++) {
const command = input[i].split(' ');
if (command[0] === 'Blacklist') {
const name = command[1];
if (friends.includes(name)) {
if (!blacklist.has(name)) {
if (name != "Lost") {
blacklist.add(name);
friends[friends.indexOf(name)] = "Blacklisted";
console.log(`${name} was blacklisted.`);
}
}
} else {
console.log(`${name} was not found.`);
}
} else if (command[0] === 'Error') {
const index = parseInt(command[1], 10);
if (index >= 0 && index < friends.length) {
const name = friends[index];
if (name != "Blacklisted") {
if (name != "Lost") {
lost.add(name);
friends[friends.indexOf(name)] = "Lost";
console.log(`${originalNames[index]} was lost due to an error.`);
}
}
}
} else if (command[0] === 'Change') {
const index = parseInt(command[1], 10);
const newName = command.slice(2).join(' ');
if (index >= 0 && index < friends.length) {
if (!(friends[index] == "Blacklisted" || friends[index] == "Lost")) {
const currentName = friends[index];
friends[index] = newName;
console.log(`${currentName} changed his username to ${newName}.`);
}
}
} else if (command[0] === 'Report') {
console.log(`Blacklisted names: ${blacklist.size}`);
console.log(`Lost names: ${lost.size}`);
console.log(`${friends.join(' ')}`);
break;
}
}
}