Hackerrank: Sock Merchant Solution
1function sockMerchant(n, ar) {2 const group = ar.reduce((acc, el) => {3 if (acc[el]) {4 acc[el] += 15 } else {6 acc[el] = 17 }8 return acc9 }, {})10 const values = Object.values(group)11 return values.map(v => Math.floor(v / 2)).reduce((acc, el) => acc + el, 0)12}
Comments
Loading comments...
Tags
hackerrank
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.