123456789101112131415161718192021 |
- export class Squares {
- constructor(private count: number) {
- }
- get sumOfSquares(): number {
- let sum = 0;
- for (let i = 0; i <= this.count; i++) {
- sum += i * i;
- }
- return sum;
- }
- get squareOfSum(): number {
- let sum = this.count * (this.count + 1) / 2;
- return sum * sum;
- }
- get difference(): number {
- return this.squareOfSum-this.sumOfSquares;
- }
- }
|