Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
Refactored the app component
Browse files Browse the repository at this point in the history
  • Loading branch information
hd-genius committed Aug 10, 2022
1 parent 8252cda commit e701ad7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CriteriaValidators } from './criteria-validators';
import { CriteriaUsageState, isUsable } from './criteria-usage-state.enum';
import { lowerCaseCharacters, upperCaseCharacters, numberCharacters, doesStringContainTypes } from './characters.util';
import { TranslateService } from '@ngx-translate/core';
import { find, distinct, take, map, combineOperators, reduce } from 'collection-ops';
import { find, distinct, take, map, filter, combineOperators, reduce } from 'collection-ops';

@Component({
selector: 'app-root',
Expand Down Expand Up @@ -75,12 +75,10 @@ export class AppComponent {
upperState === CriteriaUsageState.MUST_INCLUDE,
numberState === CriteriaUsageState.MUST_INCLUDE,
specialState === CriteriaUsageState.MUST_INCLUDE,
Array.from(specialCharacters)));


const generatedPassword = firstPasswordThatMeetsCriteria(this.generatePossiblePasswords());
Array.from(specialCharacters))
);

this.output = generatedPassword;
this.output = firstPasswordThatMeetsCriteria(this.generatePossiblePasswords());
}

public async copyPassword(): Promise<void> {
Expand All @@ -103,13 +101,15 @@ export class AppComponent {
private generatePassword(): string {
const lengthOfPassword = this.criteriaForm.get('length').value;
const validCharacters: string[] = this.determineValidCharacters();
const filterNumbersThatAreAvailable = filter(number => number < validCharacters.length);
const takeLengthOfPassword = take(lengthOfPassword);
const mapNumberToAnAvailableCharacter = map((randomIndex) => validCharacters[randomIndex % validCharacters.length]);
const mapNumberToCharacter = map(number => validCharacters[number]);
const concatCharacters = reduce((x, y) => x + y)('');

const getPasswordFromNumbers = combineOperators(
filterNumbersThatAreAvailable,
takeLengthOfPassword,
mapNumberToAnAvailableCharacter
mapNumberToCharacter
);

return concatCharacters(getPasswordFromNumbers(generateRandomNumbers()));
Expand Down

0 comments on commit e701ad7

Please sign in to comment.