Created
January 17, 2022 11:50
-
-
Save see-why/1dccfbf754ed9479abf162da4984c194 to your computer and use it in GitHub Desktop.
Interview Preparation Kit Warm Up Challenges...Sales By March
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
//https://www.hackerrank.com/challenges/sock-merchant/problem?isFullScreen=true | |
function sockMerchant(n, ar) { | |
// Write your code here | |
let count = 0; | |
let checked_numbers = []; | |
for (let item of ar){ | |
if (checked_numbers.includes(item) == false){ | |
let frequency = 0; | |
ar.forEach((value) => value == item && frequency++); | |
count += Math.floor(frequency/2); | |
} | |
checked_numbers.push(item); | |
console.log(item) | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment