+ Нов въпрос
Boyan253 0 Точки

## Problem 1 - Password Reset softuni js

let count = 0
let sum = ''
let sentencetoworkat = inp.shift()
console.log(sentencetoworkat);
while(inp[0] != "Done"){

let tokens = inp.shift().split(' ')
let name = tokens[0]
let p1 = tokens[1]
let p2 = tokens[2]

switch(name){

case"TakeOdd":
for(let el of sentencetoworkat){

if(count !== 0){
if (count % 2 !== 0 || count == 1){

sum += el
}}
count++
}console.log(sum);

break;

case "Cut":
let thisarr = sum.split('')

let spliced = thisarr.splice(p1,p2)
thisarr = thisarr.join('')
console.log(thisarr);
sum = thisarr

break;

case"Substitute":
if(sum.includes(p1)){

let replaced = sum.split(p1).join(p2)

sum = replaced

console.log(sum);
}
else{console.log("Nothing to replace!")}
break;

}
}

}

50/100

някой да вижда проблема

Тагове:
0
Axiomatik 2326 Точки
``````function password(inp) {
let count = 0
let sum = ''
let sentencetoworkat = inp.shift()

// console.log(sentencetoworkat);

while (inp[0] != "Done") {
let [name, p1, p2] = inp.shift().split(' ');
// let name = tokens[0]
// let p1 = tokens[1]
// let p2 = tokens[2]

switch (name) {
case "TakeOdd":
for (let el of sentencetoworkat) {
if (count !== 0) {
if (count % 2 !== 0 || count == 1) {
sum += el;
}
}

count++;
}
count = 0;
sentencetoworkat = sum;
sum = '';
console.log(sentencetoworkat);

break;
case "Cut":
// let thisarr = sum.split('')
// let spliced = thisarr.splice(p1, p2)
// thisarr = thisarr.join('')
// console.log(thisarr);
let index = Number(p1);
let length = Number(p2);
let substring = sentencetoworkat.substring(index, index + length);
sentencetoworkat = sentencetoworkat.replace(substring, '');
console.log(sentencetoworkat);

break;
case "Substitute":
if (sentencetoworkat.includes(p1)) {
let replaced = sentencetoworkat.split(p1).join(p2)
sentencetoworkat = replaced;

console.log(sentencetoworkat);
} else { console.log("Nothing to replace!") }

break;
}
}