feat: rename prime to random

This commit is contained in:
thomas
2023-11-03 20:40:29 +01:00
parent bc6449cf57
commit b521f45f4a
5 changed files with 36 additions and 44 deletions

View File

@@ -0,0 +1,30 @@
import { Injectable, computed, signal } from '@angular/core';
@Injectable()
export class HeavyCalculationService {
private finalLength = 664579;
private loadingLength = signal(0);
loadingPercentage = computed(
() => (this.loadingLength() * 100) / this.finalLength
);
startLoading() {
this.randomHeavyCalculalationFunction();
}
private randomHeavyCalculalationFunction() {
for (let num = 2; num <= 10000000; num++) {
let randomFlag = true;
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) {
randomFlag = false;
break;
}
}
if (randomFlag) {
this.loadingLength.update((l) => l + 1);
}
}
}
}