-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (37 loc) · 1.13 KB
/
index.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
function findDup(str) {
let arr = str.split('');
let strCount = {};
let arrDup = [];
arr.map((value) => {
strCount[value] = strCount[value] ? strCount[value]+1 : 1;
})
for(abjad in strCount) {
if(strCount[abjad] > 1) {
arrDup.push(abjad);
}
}
return arrDup.sort().join().replaceAll(',', '');
}
function findDup2(words){
let duplicate_word = []
for(let i = 0; i < words.length; i++){
if(duplicate_word.indexOf(words[i]) < 0 && words.indexOf(words[i], i+1) >=0)
duplicate_word.push(words[i])
}
return duplicate_word.sort().join().replace(/,/g,'')
}
function findDup3(input) {
let arrayString = {}
input.split('').map(item => arrayString[item] = arrayString[item] ? arrayString[item]+1 : 1)
return Object.keys(arrayString).filter(item => arrayString[item] > 1).sort().join().replaceAll(',','')
}
function eliDup(str) {
let arr = str.split('');
let arrEli = [];
arr.map((value) => {
if(arrEli.indexOf(value) === -1) {
arrEli.push(value);
}
})
return arrEli.sort().join().replaceAll(',', '');
}