-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDna.js
38 lines (35 loc) · 982 Bytes
/
Dna.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
function findRepeatedDnaSequences(s) {
let emptyObject = {};
let result = [];
for (let i = 0; i <= s.length - 10; i++) {
let substring = s.substring(i, i + 10);
if (emptyObject[substring]) {
if(emptyObject[substring]===1){
result.push(substring);
}
emptyObject[substring] += 1;
}
else {
emptyObject[substring] = 1;
}
}
return result;
}
console.log(findRepeatedDnaSequences("ACGACGACGACGACGACGACG"));
function findRepeatedDnaSequencess(s) {
let map = new Map();
let result = [];
for (let i = 0; i <= s.length - 10; i++) {
let substring = s.substring(i, i + 10);
if (map.has(substring)) {
if(map.get(substring) === 1){
result.push(substring);
}
map.set(substring, map.get(substring) + 1);
} else {
map.set(substring, 1);
}
}
return result;
}
console.log(findRepeatedDnaSequencess("ACGACGACGACGACGACGACG"));