Skip to content

Commit

Permalink
feat(ngx-combination-generator): added unique parameter to load the c…
Browse files Browse the repository at this point in the history
…ombinations
  • Loading branch information
AnthonyNahas committed Apr 18, 2018
1 parent d9cfb38 commit a4e5867
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/module/service/ngx-combination-generator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export class NgxCombinationGeneratorService {
return `Hello ${name || 'Stanger'}!`;
}

loadCombinationList(charList: string[], minCharCount: number, maxCharCount: number): string[] {
isUnique(str: string) {
const repeats = /(.)\1/;
return repeats.test(str)
}

loadCombinationList(charList: string[], minCharCount: number, maxCharCount: number, unique: boolean = false): string[] {
let currentCode = '';
let currentCodeLength = minCharCount; // get the first code to work with as a starting point.
const comboList = [],
Expand All @@ -35,7 +40,13 @@ export class NgxCombinationGeneratorService {
charPos[currentCodeLength - 1]++;

// save the code into the array
comboList.push(currentCode);
if (unique) {
if (!this.isUnique(currentCode)) {
comboList.push(currentCode);
}
} else {
comboList.push(currentCode);
}

// now handle overflow - gotta go through array backwards
let overflowCount = 0;
Expand Down

0 comments on commit a4e5867

Please sign in to comment.