mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-13 14:23:02 -05:00
feat: rename prime to random
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user