Skip to content

Instantly share code, notes, and snippets.

@kerren
Created July 10, 2019 20:37
Show Gist options
  • Select an option

  • Save kerren/a97651300551f5d7a83a11733d9174be to your computer and use it in GitHub Desktop.

Select an option

Save kerren/a97651300551f5d7a83a11733d9174be to your computer and use it in GitHub Desktop.
The new Looped Random Number Generator Service
import { Injectable } from '@nestjs/common';
import { RandomNumberService } from './random-number.service';
import {
defaultLoopedRandomNumberServiceOptions,
LoopedRandomNumberServiceOptions,
} from './looped-random-number-service-options';
@Injectable()
export class LoopedRandomNumberService {
private options: LoopedRandomNumberServiceOptions;
constructor(
options: Partial<LoopedRandomNumberServiceOptions>,
private readonly randomNumberService: RandomNumberService,
) {
this.options = Object.assign(
{},
defaultLoopedRandomNumberServiceOptions,
options,
);
}
generate(): number {
let result = 0;
for (let i = 0; i < this.options.loops; i++) {
result += this.randomNumberService.generate();
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment