minor refactor

This commit is contained in:
eneller
2025-04-23 12:42:39 +02:00
parent e023ee2453
commit 2c27570e2b
2 changed files with 6 additions and 3 deletions

View File

@@ -36,6 +36,7 @@
</form>
<table class="table table-striped custom-table">
<caption *ngIf="duplicateNames.length >0">Removed: {{ duplicateNames }}</caption>
<thead>
<tr>
<th scope="col">Size</th>

View File

@@ -18,7 +18,7 @@ export class AppComponent implements OnInit {
numTeamsSelected = 2;
nTeamsValue = "4";
teamsArray: string[][] = [];
displayedColumns = ["teamCount", "teamNames"];
duplicateNames: string[] = [];
constructor(private activatedRoute: ActivatedRoute){}
@@ -38,12 +38,14 @@ export class AppComponent implements OnInit {
else{
this.numTeamsSelected = Number(this.numTeamsSelectorValue);
}
let names = this.playerNamesValue
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
names = [...new Set(names)];
let namesset = new Set(nameslist);
let names = [...namesset];
var teams = Array.from({ length: this.numTeamsSelected }, () => []);
var playersPerTeam = Math.floor(names.length / this.numTeamsSelected);