Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Find the odd int
- // Given an array, find the int that appears an odd number of times.
- // There will always be only one integer that appears an odd number of time
- function findOdd(A) {
- //happy coding!
- const count = A.reduce((count, index) => {
- if (count.hasOwnProperty(index)) {
- count[index] += 1
- } else {
- count[index] = 1
- }
- return count;
- }, {});
- var oddInteger
- for (var property in count) {
- if (count[property] % 2 != 0) {
- oddInteger = property;
- }
- }
- return Number(oddInteger);
- }
- 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