function parse(res) {
let number = 0;
for (let el of res) {
if (el == 'i') {
number++;
}
if (el == 'd') {
number--;
}
if (el == 's') {
number *= number;
}
if (el == 'o') {
return [number];
}
}
return number;
}
console.log(parse('iiisdoso'));
function parse(res) {
let number = 0;
for (let el of res) {
if (el == 'i') {
number++;
}
if (el == 'd') {
number--;
}
if (el == 's') {
number *= number;
}
if (el == 'o') {
return [number];
}
}
if (!number) {
return 'Error, not found'; // или throw new Error('Error, not found');
}
return number;
}