Skip to content

Instantly share code, notes, and snippets.

@Stefanacef
Created October 13, 2021 11:37
Show Gist options
  • Save Stefanacef/2684b7bba0ab73d5d78d912013a4e1e6 to your computer and use it in GitHub Desktop.
Save Stefanacef/2684b7bba0ab73d5d78d912013a4e1e6 to your computer and use it in GitHub Desktop.
Solution for "Sales by Match" in Hackerrank
const ar = [10, 20, 20, 10, 10, 30, 50, 10, 20];
const n = 9;
function sockMerchant(n, ar) {
let count = 0;
ar.sort((a, b) => a - b);
for (let i = 0; i < ar.length; i++) {
if (ar[i] === ar[i + 1]) {
i++
count++;
}
}
console.log(count);
}
sockMerchant(n, ar);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment