forked from kokonior/Javascript-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathakbarhabiby.js
61 lines (55 loc) · 1.57 KB
/
akbarhabiby.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
54
55
56
57
58
59
60
61
// * run with node akbarhabiby.js _input-text_
const [, , ...inputs] = process.argv;
const input = [...inputs].join(" ");
const board = [
["*", "*", "*", 10],
["*", "*", -5, -10, "*", 100],
["a", "A", "o", "b"],
];
const arrOfNums = [
[[20, 10], [15], [1, 1]],
[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [2], [9, 11]],
[[3, 5, 1], [1, 5, 3], [1]],
[[2]],
];
// * Fizz-Buzz
const fizzBuzz = (min = 1, max = 100) => {
const arr = [];
for (let i = min; i <= max; i++) {
let temp = [];
if (i % 3 === 0) temp.push("Fizz");
if (i % 5 === 0) temp.push("Buzz");
arr.push(temp.length > 0 ? temp.join("") : i);
}
return arr;
};
const reverseText = (text = "") => {
return text
.split("")
.map((_, i) => text[text.length - (1 + i)])
.join("");
};
const vocalSeeker = (board = [[]], vocals = "AIUEO") => {
const result = board
.map((arr) =>
arr
.map((el) =>
typeof el === "string"
? vocals.split("").find((v) => v === el.toUpperCase())
? el
: ""
: ""
)
.join("")
)
.join("");
return `vokal ditemukan ${result.length} dan kumpulan vokal adalah ${result}`;
};
const deepSum = (input = [[[]]], sum = 0) => {
input.forEach((l1) => l1.forEach((l2) => l2.forEach((l3) => (sum += l3))));
return sum; // * not fully dynamic
};
console.log("FizzBuzz =>", fizzBuzz(), "\n");
console.log("ReverseText =>", reverseText(input ? input : "Hello World"), "\n");
console.log("VocalSeeker =>", vocalSeeker(board), "\n");
console.log("DeepSum =>", deepSum(arrOfNums));