Skip to content

Commit 574fb1f

Browse files
author
Rosty Siryk (c)
committed
feat(anagram): custom divider
1 parent 43dab9e commit 574fb1f

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

src/app/generator/components/anagrammator/anagrammator.component.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
<div class="container">
22
<h1>Анаграматор</h1>
3-
<mat-form-field class="input word" appearance="outline">
4-
<mat-label>Зробити анаграму з:</mat-label>
5-
<input type="text" matInput value="Слово" (keyup)="setSourceString($event)">
6-
</mat-form-field>
3+
<div class="inputs">
4+
<mat-form-field class="input word" appearance="outline">
5+
<mat-label>Зробити анаграму з:</mat-label>
6+
<input type="text" matInput [value]="sourceWord" (keyup)="setSourceString($event)">
7+
</mat-form-field>
8+
<mat-form-field class="input word" appearance="outline">
9+
<mat-label>Розділовий знак:</mat-label>
10+
<input type="text" matInput [value]="divider" (keyup)="setDivider($event)">
11+
</mat-form-field>
12+
</div>
713
<div>Фільтр результатів:</div>
814
<div class="filters">
915
<mat-form-field class="input start-with" (keyup)="setStartWith($event)" appearance="outline">

src/app/generator/components/anagrammator/anagrammator.component.scss

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
:host {
22
display: block;
33

4+
pre#result-render {
5+
margin-top: 0;
6+
font-size: 50px;
7+
line-height: 70px;
8+
font-family: Arial, Helvetica, sans-serif;
9+
}
10+
411
.rootenia {
512
font-family: var(--rutenia-akcidenta-font) !important;
613
}
714

815
.container {
916
margin: 1em;
1017

18+
.inputs {
19+
display: grid;
20+
grid-template-columns: 30% 17%;
21+
gap: 3%;
22+
}
23+
1124
.filters {
1225
display: grid;
1326
grid-template-columns: 30% 30% 30%;
@@ -36,12 +49,6 @@
3649
margin-right: .2em;
3750
}
3851
}
39-
40-
pre {
41-
margin-top: 0;
42-
font-size: 80px;
43-
line-height: 90px;
44-
}
4552
}
4653

4754
.axes {

src/app/generator/components/anagrammator/anagrammator.component.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { AfterViewInit, Component, OnInit } from '@angular/core';
22
import { copyToClipboardWithVisualResponse } from '../../generator-helpers';
33

44
@Component({
@@ -7,12 +7,13 @@ import { copyToClipboardWithVisualResponse } from '../../generator-helpers';
77
styleUrls: ["./anagrammator.component.scss"],
88
})
99
export class AnagrammatorComponent implements OnInit {
10-
11-
capitalizeOutput = false;
12-
shuffle = false;
10+
11+
sourceWord = "Символ";
12+
divider = "";
13+
capitalizeOutput = true;
14+
shuffle = true;
1315
toUseRutenia = false;
1416

15-
sourceWord = "";
1617
anagrams = [""];
1718
filtered = [""];
1819
formattedResult = "";
@@ -28,6 +29,11 @@ export class AnagrammatorComponent implements OnInit {
2829
this.anagrammate();
2930
}
3031

32+
setDivider($event: KeyboardEvent) {
33+
this.divider = ($event.currentTarget as HTMLInputElement).value;
34+
this.anagrammate();
35+
}
36+
3137
setSourceString(event: any) {
3238
this.sourceWord = event?.target?.value;
3339
this.anagrammate();
@@ -82,11 +88,12 @@ export class AnagrammatorComponent implements OnInit {
8288
(remaining = "") => {
8389
const res = [item].concat(remaining);
8490
const id = item + remaining;
85-
result[id] = res.join(divider);
91+
let joined: string = res.join("");
8692
if (this.capitalizeOutput) {
87-
result[id] = result[id].toLowerCase();
88-
result[id] = result[id].substring(0, 1).toUpperCase() + result[id].substring(1);
89-
}
93+
joined = joined.toLowerCase();
94+
joined = joined.charAt(0).toUpperCase() + joined.substring(1);
95+
}
96+
result[id] = joined;
9097
}
9198
);
9299
});
@@ -111,10 +118,10 @@ export class AnagrammatorComponent implements OnInit {
111118
this.iteration = 0;
112119

113120
this.anagrams = this.combineItems(
114-
this.sourceWord.split(""),
121+
this.sourceWord.split(this.divider),
115122
this.maxIterations,
116123
0,
117-
""
124+
this.divider
118125
);
119126
const filteredByStart = this.startWith
120127
? this.anagrams.filter((str) => str.indexOf(this.startWith) === 0)

0 commit comments

Comments
 (0)