Quick actions

cmd+k|ctrl+k

Navigation

Languages

CalculatingĀ  sales by Math šŸ©Ā 

Snippet info

Language

JavaScript

Visibility

public

Author

krishnakanth

Created

2022-11-23T16:08:38.257115Z

Updated

2022-11-24T02:55:02.828756Z

//also use arr.reverse
function processData(input) {
    
    let new_arr =[]
    let res = 0
    let string = input.split('\n');
    let n = string[0]
    let ar = string[1].split(" ").map(Number)
    const arr = new Set(ar);
    arr.forEach( a => new_arr.push(ar.count(a)))
    new_arr.forEach( a => res += Math.floor(a/2)  )
    console.log(res)
    
   // console.log(Math.floor(3/2))
}

Array.prototype.count = function(value) {
    let count = 0;

    this.forEach(item => {
	if (item === value) {
	    count++;
	}
    });

    return count;
}  
            
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
    processData(_input);
});

        
INFO