Проблем с 01. World Tour от 02. Programming Fundamentals Final Exam
Здравейте, получавам 83/100 и Test #6 (Time limit), а иначе всички отговори са верни, някой може ли да ми помогне ?
Благодаря :)
задача: https://judge.softuni.org/Contests/Practice/Index/2518#0
код:
function solve(input) {
let str = input.shift()
const actions = { "Add Stop": addStop, "Remove Stop": remove, Switch: switched }
function addStop(index, newPart){
if(index !== undefined){
index = Number(index)
let firstPart = str.substring(0, index);
let secondPart = str.substring(index);
str = firstPart + newPart + secondPart;
}
console.log(str)
}
function remove(startIndex, endIndex){
startIndex = Number(startIndex);
endIndex = Number(endIndex);
if (startIndex !== undefined && endIndex !== undefined) {
let cut = str.substring(startIndex, endIndex + 1);
str = str.replace(cut, "")
}
console.log(str)
}
function switched(oldItem, newItem){
if(str.includes(oldItem)){
while (str.includes(oldItem)) {
str = str.replace(oldItem, newItem)
}
}
console.log(str)
}
for (let i = 0; i < input.length; i++) {
let[command, a, b] = input[i].split(":")
if(input[i] === "Travel") break
actions[command](a, b)
}
console.log(`Ready for world tour! Planned stops: ${str}`)
}
Благодаря!
After reading your instructions, I discovered the problems and solved them, elastic man. Hope you will continue to share such useful methods.