DEV Community

Discussion on: #22 - Find the unique number CodeWars Kata (6 kyu)

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ • Edited
const findUniq = (a,s=a.sort())=>s[s[1]-s[0]?0:s.length-1]
Enter fullscreen mode Exit fullscreen mode

Sort the array, check if first two elements are equal - if they are, unique is last element, otherwise it's the first element

Collapse
 
cesar__dlr profile image
Cesar Del rio

Makes sense bro, great solution! πŸ™Œ