Skip to content

Commit 36af05f

Browse files
author
Wakidur Rahaman
committed
covert js file
1 parent d090cd6 commit 36af05f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Google Question
2+
/**
3+
* Given an array = [2, 5, 1, 2, 3, 5, 1, 2, 4]: It should return 2
4+
*
5+
* Given an array = [2, 1, 1, 2, 3, 5, 1, 2, 4]: It should return 1
6+
*
7+
* Given an array = [2, 3, 4, 5]: It should return undefined
8+
*
9+
*/
10+
// Solution 01:
11+
function firstRecurringCharacter(array) {
12+
for (var i = 0; i < array.length; i++) {
13+
var element = array[i];
14+
console.log('first : ', element);
15+
for (var j = i + 1; j < array.length; j++) {
16+
var element_1 = array[j];
17+
console.log('Second : ', element, element_1);
18+
if (array[i] === array[j]) {
19+
console.log(array[i]);
20+
return array[i];
21+
}
22+
}
23+
}
24+
console.log('Nothing match : undefined');
25+
return undefined;
26+
}
27+
var array01 = [2, 5, 1, 0, 3, 5, 1, 2, 4];
28+
var array02 = [2, 1, 1, 2, 3, 5, 1, 2, 4];
29+
var array03 = [2, 3, 4, 5];
30+
// Call function
31+
firstRecurringCharacter(array01);

0 commit comments

Comments
 (0)