Given a string remove all + present together in the string. Javascript Program

Input string =’a+++b++c+’;

Table of Contents

Output String=a+b+c+

Source Code

let str='a+++b++c+';
let outStr='';
let len=str.length;
for(let i=0;i<len;i++)
{
    if(str[i]=='+'&&str[i+1]=='+')
    {
        outStr=outStr+'';

    }
    else
    {
        outStr=outStr+str[i];
    }
}
console.log(outStr);

Leave a Reply

Your email address will not be published. Required fields are marked *