Advertisement
Coldsewoo

Untitled

Oct 17th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const arr = [3, 5, 5, 4, 3, 4, 8, 8, 2]
  2.  
  3. function findSingle(arr) {
  4.   const set = new Set()
  5.   while(arr.length) {
  6.     let temp = arr.pop()
  7.     if(!set.has(temp)) set.add(temp)
  8.     else set.delete(temp)
  9.   }
  10.   return Array.from(set.values()).pop() || null
  11. }
  12.  
  13. findSingle(arr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement