📜  Sales by Matchhackerrank 解决方案 javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:20.392000             🧑  作者: Mango

代码示例1
// Sales by Match hackerrank solution javascript
function sockMerchant(n, ar) {
    // Write your code here
    let pairsCount = 0;
  let counterObj = {};

  for (let sock of ar) {
    if (!counterObj[sock]) {
      counterObj[sock] = 1;
    } else {
      counterObj[sock] = counterObj[sock] + 1;

      if (counterObj[sock] === 2) {
        pairsCount++;
        counterObj[sock] = 0;
      }
    }
  }
  return pairsCount;
}