Sales by Match

  • + 0 comments

    In Js:

    function sockMerchant(n, ar) {
        // Write your code here
        let duplicate = [];
        let sar = ar.sort((a, b) => a- b);
        for(let i=0; i<n; i++){
            if(sar[i] === sar[i+1]){
                duplicate.push(sar[i]);
                ++i;
            }
        }
        return duplicate.length;
    }