-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinding Duplicates(Strings).js
53 lines (51 loc) · 1.31 KB
/
Finding Duplicates(Strings).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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* eslint-disable */
let sample = [
["a", "a", "b", "b"],
["a", "a", "b", "b"],
["b", "a", "a", "b"],
["a", "b", "a", "b"],
["a", "b", "a", "b"],
["b", "a", "a", "b"],
["b", "a", "a", "b"],
["a", "b", "a", "b"],
["a", "b", "a", "b"],
["b", "a", "a", "b"],
["a", "a", "b", "b"],
["a", "a", "b", "b"],
["a", "b", "b", "a"],
["b", "a", "b", "a"],
["b", "a", "b", "a"],
["a", "b", "b", "a"],
["b", "b", "a", "a"],
["b", "b", "a", "a"],
["b", "b", "a", "a"],
["b", "b", "a", "a"],
["a", "b", "b", "a"],
["b", "a", "b", "a"],
["b", "a", "b", "a"],
["a", "b", "b", "a"],
];
const verifyDuplicates = (arr) => {
let sample_string = arr.join(" ");
let sample_copy = sample_string.split(" ");
let convertedOutput = [];
let output = [];
for (let i = 0; i < sample_copy.length - 1; i++) {
let valueToCompare = sample_copy[i];
for (let e = 1; e < sample_copy.length - 1; e++) {
if (valueToCompare.toString() === sample_copy[e].toString()) {
if (output.indexOf(valueToCompare) === -1) {
output.push(valueToCompare);
break;
} else {
break;
}
}
}
}
for (let i = 0; i < output.length - 1; i++) {
convertedOutput.push(output[i].split(","));
}
return convertedOutput;
};
console.log(verifyDuplicates(sample));