• + 0 comments

    JS solution

    function gemstones(arr) {
        
        // remove duplictions in each string 
            
            let strs = [];
            for(const i of arr){
                
                    strs.push(i.split('').filter((a,index)=>i.indexOf(a)===index).join(''));
                
            }
            
     console.log(strs);
        let counts = {};
        for(const i of strs){
            for(const j of i){
                if(i.split('').includes(j))
                counts[j] = (counts[j]||0)+1;
            }
        }
        let counter = 0;
        for(const i in counts){
            if(counts[i]===arr.length){
                counter++;
            }
        }
       return (counter);
    }