-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
79 lines (59 loc) · 1.25 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
export const DEFAULT_GENERATION = 6;
export const originalParts = [
"Allah",
"Saglik",
"Para",
"Ask",
"Versin",
"Amin",
];
export class AspavaGenerator {
constructor(parts = originalParts) {
this.parts = parts;
}
get(n) {
return this.parts[n % this.parts.length];
}
getAll() {
return this.parts;
}
getAsString() {
return this.parts.join(" ");
}
getFirstLetters() {
return this.parts.map((part) => part[0]).join("");
}
shuffle() {
this.parts = this.parts.toSorted(() => Math.random() - 0.5);
return this;
}
ascending() {
this.parts = this.parts.toSorted((a, b) => a.localeCompare(b));
return this;
}
descending() {
this.parts = this.parts.toSorted((a, b) => b.localeCompare(a));
return this;
}
upper() {
this.parts = this.parts.map((part) => part.toUpperCase());
return this;
}
lower() {
this.parts = this.parts.map((part) => part.toLowerCase());
return this;
}
*generator(n = DEFAULT_GENERATION) {
let i = 0;
while (i < n) {
yield this.get(i++);
}
}
}
export const aspava = new AspavaGenerator();
export default aspava;
if (import.meta.main) {
for (const part of aspava.upper().generator()) {
console.log(part);
}
}