Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/utils/numberUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Number utility functions
export function randomBetween(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
export function percentage(value: number, total: number): number {
if (total === 0) return 0;
return Math.round((value / total) * 100);
}
export function roundTo(num: number, decimals: number): number {
const factor = Math.pow(10, decimals);
return Math.round(num * factor) / factor;
}
export function ordinal(n: number): string {
const s = ['th', 'st', 'nd', 'rd'];
const v = n % 100;
return n + (s[(v - 20) % 10] || s[v] || s[0]);
}
export function range(start: number, end: number, step: number = 1): number[] {
const result: number[] = [];
for (let i = start; i <= end; i += step) result.push(i);
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: range can enter an infinite loop and does not handle descending ranges because the loop condition ignores step direction and zero-step input.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/utils/numberUtils.ts, line 20:

<comment>`range` can enter an infinite loop and does not handle descending ranges because the loop condition ignores step direction and zero-step input.</comment>

<file context>
@@ -0,0 +1,22 @@
+}
+export function range(start: number, end: number, step: number = 1): number[] {
+  const result: number[] = [];
+  for (let i = start; i <= end; i += step) result.push(i);
+  return result;
+}
</file context>
Fix with Cubic

return result;
}
Loading