Skip to content
Closed
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
31 changes: 31 additions & 0 deletions helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export function formatString(input: string): string {
return input.trim().toLowerCase().replace(/\s+/g, '-');
}

export function calculateSum(numbers: number[]): number {
return numbers.reduce((acc, num) => acc + num, 0);
}
Comment on lines +5 to +7
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove calculateSum function - violates organizational standards.

According to the documented organizational constraint, the calculateSum function should NOT be included in helper.ts because it already exists elsewhere in the codebase. This violates the established architectural guideline.

Remove this function to comply with organizational standards:

-export function calculateSum(numbers: number[]): number {
-  return numbers.reduce((acc, num) => acc + num, 0);
-}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function calculateSum(numbers: number[]): number {
return numbers.reduce((acc, num) => acc + num, 0);
}
🤖 Prompt for AI Agents
In helper.ts around lines 5 to 7, remove the entire calculateSum function
because it duplicates functionality that already exists elsewhere in the
codebase, violating organizational standards. Delete the function declaration
and its implementation to comply with the architectural guidelines.


export function isValidEmail(email: string): boolean {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}

export function debounce<T extends (...args: any[]) => any>(
func: T,
delay: number
): (...args: Parameters<T>) => void {
let timeoutId: NodeJS.Timeout;
return (...args: Parameters<T>) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => func(...args), delay);
};
}
Comment on lines +14 to +23
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Address return type and environment compatibility issues.

The debounce function has a few issues:

  1. Return value loss: The debounced function returns void but the original function may return a value
  2. Environment assumption: NodeJS.Timeout assumes Node.js environment but may be used in browsers

Consider this improved implementation:

export function debounce<T extends (...args: any[]) => any>(
  func: T,
  delay: number
): (...args: Parameters<T>) => void {
  let timeoutId: ReturnType<typeof setTimeout>;
  return (...args: Parameters<T>) => {
    clearTimeout(timeoutId);
    timeoutId = setTimeout(() => func(...args), delay);
  };
}

Note: If you need to preserve the return value, consider implementing a promisified version or document that debounced functions don't return values.

🤖 Prompt for AI Agents
In helper.ts around lines 14 to 23, the debounce function currently returns
void, losing the original function's return value, and uses NodeJS.Timeout which
assumes a Node.js environment. To fix this, change the timeoutId type to
ReturnType<typeof setTimeout> for cross-environment compatibility, and update
the return type of the debounced function to void, documenting that the
debounced function does not return the original function's return value or
consider a promisified version if return values are needed.


export function chunk<T>(array: T[], size: number): T[][] {
const chunks: T[][] = [];
for (let i = 0; i < array.length; i += size) {
chunks.push(array.slice(i, i + size));
}
return chunks;
}