-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.js
37 lines (29 loc) · 744 Bytes
/
9.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Function to find the
function findSingle(A, ar_size)
{
// Iterate over every element
for (let i = 0; i < ar_size; i++) {
// Initialize count to 0
let count = 0;
for (let j = 0; j < ar_size; j++) {
// Count the frequency
// of the element
if (A[i] == A[j]) {
count++;
}
}
// if the frequency of the
// element is one
if (count == 1) {
return A[i];
}
}
// if no element exist at most once
return -1;
}
// Driver code
let ar = [ 2, 3, 5, 4, 5, 3, 4 ];
let n = 7;
// Function call
document.write("Element occurring once is "
+ findSingle(ar, n));