Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. // Find the odd int
  2. // Given an array, find the int that appears an odd number of times.
  3.  
  4. // There will always be only one integer that appears an odd number of time
  5.  
  6. function findOdd(A) {
  7. //happy coding!
  8. const count = A.reduce((count, index) => {
  9. if (count.hasOwnProperty(index)) {
  10. count[index] += 1
  11. } else {
  12. count[index] = 1
  13. }
  14. return count;
  15. }, {});
  16. var oddInteger
  17. for (var property in count) {
  18. if (count[property] % 2 != 0) {
  19. oddInteger = property;
  20. }
  21. }
  22.  
  23.  
  24. return Number(oddInteger);
  25. }
  26.  
  27. findOdd([20, 1, -1, 2, -2, 3, 3, 5, 5, 1, 2, 4, 20, 4, -1, -2, 5])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement