• + 2 comments

    I saw the code in your PM. The performance hit was in your for loop. You were checking to see if one substring had the other substring's character twice (once with includes() and once with indexOf()). Both those functions will search for the given character in a string/array, but includes() will return true or false and indexOf() will return the index of the character or -1 if it doesn't contain the character. So, if you only use indexOf() and check if the return value is === -1 instead of searching through the string twice. Below is an edited version of the code you sent me and you will see what i mean:

        let l=s.length,c=0,c1,c2;
    
        if(l%2==0){
            c1=s.slice(0,l/2).split("");
            c2=s.slice(l/2).split("");
            let l2=c1.length;
    
            for(let i=0;i<l2;i++){
                let id = c2.indexOf(c1[i]);
                if(id !== -1){
                    c2[id]=" ";
                }
                else{ c+=1; }
            }
        }
        else{ return "-1"; }
    return c;