-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch.js
40 lines (38 loc) · 822 Bytes
/
fetch.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
const word = "aaaab";
let newarr = [];
let finalArr = [];
let count = 0;
let boolen = false;
if (word === "abc") {
count;
} else {
for (let i = 0; i <= word.length - 1; i++) {
for (let w = 1; w <= word[i].length; w++) {
if (word[i] === "a" && word[w] === "b") {
count += 3;
}
}
switch (word[i]) {
case "a":
newarr.push({ a: "b", b: "a", c: "c" });
break;
case "b":
newarr.push({ a: "a", b: "b", c: "c" });
break;
case "c":
newarr.push({ a: "a", b: "c", c: "b" });
default:
break;
}
if (!boolen) {
++i;
}
}
newarr.forEach((value) => {
finalArr.push(Object.values(value).join().replaceAll(",", ""));
});
newarr = [];
}
count += finalArr.length * 2;
finalArr = [];
console.log(count);