Created
October 13, 2021 11:37
-
-
Save Stefanacef/2684b7bba0ab73d5d78d912013a4e1e6 to your computer and use it in GitHub Desktop.
Solution for "Sales by Match" in Hackerrank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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