• API
• FAQ
• Tools
• Archive
daily pastebin goal
22%
SHARE
TWEET

# Untitled

a guest Mar 22nd, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top