diff --git a/src/app/app.component.html b/src/app/app.component.html index 15b378d..14367f7 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,59 +1,5 @@
-
-

Please select the number of teams:

- - -
-
- - -
- -
- - - - - - - - - - - @for (team of teamsArray; track $index) { - - - - - } - -
Removed: {{ duplicateNames }}
SizeNames
{{ team.length | number }}{{ team }}
- -
+
diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 292df5e..aa06ab2 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -5,10 +5,11 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { CommonModule } from '@angular/common'; import { filter, take } from 'rxjs'; +import { ScreenBasicComponent } from "./screen-basic/screen-basic.component"; @Component({ selector: 'app-root', - imports: [NgbModule, RouterOutlet, CommonModule, FormsModule], + imports: [NgbModule, RouterOutlet, CommonModule, FormsModule, ScreenBasicComponent], templateUrl: './app.component.html', styleUrl: './app.component.less' }) @@ -35,7 +36,7 @@ export class AppComponent implements OnInit { }); } - onButtonGenerate(textinput: string): void{ +onButtonGenerate(textinput: string): void{ if(this.numTeamsSelectorValue === 'n'){ this.numTeamsSelected = Number(this.nTeamsValue); } diff --git a/src/app/screen-basic/screen-basic.component.html b/src/app/screen-basic/screen-basic.component.html new file mode 100644 index 0000000..94b1fb3 --- /dev/null +++ b/src/app/screen-basic/screen-basic.component.html @@ -0,0 +1,55 @@ +
+

Please select the number of teams:

+ + +
+
+ + +
+ +
+ + + + + + + + + + + @for (team of teamsArray; track $index) { + + + + + } + +
Removed: {{ duplicateNames }}
SizeNames
{{ team.length | number }}{{ team }}
+ +
diff --git a/src/app/screen-basic/screen-basic.component.less b/src/app/screen-basic/screen-basic.component.less new file mode 100644 index 0000000..e69de29 diff --git a/src/app/screen-basic/screen-basic.component.spec.ts b/src/app/screen-basic/screen-basic.component.spec.ts new file mode 100644 index 0000000..68482f0 --- /dev/null +++ b/src/app/screen-basic/screen-basic.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ScreenBasicComponent } from './screen-basic.component'; + +describe('ScreenBasicComponent', () => { + let component: ScreenBasicComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ScreenBasicComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(ScreenBasicComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/screen-basic/screen-basic.component.ts b/src/app/screen-basic/screen-basic.component.ts new file mode 100644 index 0000000..0d19843 --- /dev/null +++ b/src/app/screen-basic/screen-basic.component.ts @@ -0,0 +1,60 @@ +import { Component, OnInit} from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { RouterOutlet, ActivatedRoute } from '@angular/router'; +import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; +import { CommonModule } from '@angular/common'; + +@Component({ + selector: 'app-screen-basic', + imports: [NgbModule, RouterOutlet, CommonModule, FormsModule, ScreenBasicComponent], + templateUrl: './screen-basic.component.html', + styleUrl: './screen-basic.component.less' +}) +export class ScreenBasicComponent { + playerNamesValue = ""; + numTeamsSelectorValue = "2"; + numTeamsSelected = 2; + nTeamsValue = "4"; + teamsArray: string[][] = []; + duplicateNames: string[] = []; + + onButtonGenerate(textinput: string): void{ + if(this.numTeamsSelectorValue === 'n'){ + this.numTeamsSelected = Number(this.nTeamsValue); + } + else{ + this.numTeamsSelected = Number(this.numTeamsSelectorValue); + } + let nameslist = this.playerNamesValue + .split('\n') + .map(function(str){return str.trim();}) + .filter(function(str){return str}); // boolean interpretation is same as non-empty + // remove duplicates by using a Set + let namesset = new Set(nameslist); + let names = [...namesset]; + + + let teams = Array.from({ length: this.numTeamsSelected }, () => []); + let playersPerTeam = Math.floor(names.length / this.numTeamsSelected); + + let nameslen = names.length; + function* iter(list: any[]){ + let index = 0; + while(true){ + yield list[index % list.length]; + index++; + } + } + let iterator = iter(teams); + for(let i =0; i < nameslen; i++){ + let index = Math.floor(Math.random()* names.length); + let n = names[index]; + names.splice(index,1); + let team = iterator.next().value; + team.push(n); + + } + this.teamsArray = teams; + } + +} \ No newline at end of file