- Notifications
You must be signed in to change notification settings - Fork6
Add helper.ts#77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,31 @@ | ||||||||||||||||||||||||||||||||||||||||||
| exportfunctionformatString(input:string):string{ | ||||||||||||||||||||||||||||||||||||||||||
| returninput.trim().toLowerCase().replace(/\s+/g,'-'); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| exportfunctioncalculateSum(numbers:number[]):number{ | ||||||||||||||||||||||||||||||||||||||||||
| returnnumbers.reduce((acc,num)=>acc+num,0); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| exportfunctionisValidEmail(email:string):boolean{ | ||||||||||||||||||||||||||||||||||||||||||
| constemailRegex=/^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||||||||||||||||||||||||||||||||||||||||||
| returnemailRegex.test(email); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| exportfunctiondebounce<Textends(...args:any[])=>any>( | ||||||||||||||||||||||||||||||||||||||||||
| func:T, | ||||||||||||||||||||||||||||||||||||||||||
| delay:number | ||||||||||||||||||||||||||||||||||||||||||
| ):(...args:Parameters<T>)=>void{ | ||||||||||||||||||||||||||||||||||||||||||
| lettimeoutId:NodeJS.Timeout; | ||||||||||||||||||||||||||||||||||||||||||
| return(...args:Parameters<T>)=>{ | ||||||||||||||||||||||||||||||||||||||||||
| clearTimeout(timeoutId); | ||||||||||||||||||||||||||||||||||||||||||
| timeoutId=setTimeout(()=>func(...args),delay); | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines +14 to +23 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. 🛠️ Refactor suggestion Fix timeout initialization and consider return value handling. Two potential improvements:
export function debounce<T extends (...args: any[]) => any>( func: T, delay: number ): (...args: Parameters<T>) => void {- let timeoutId: NodeJS.Timeout;+ let timeoutId: NodeJS.Timeout | undefined; return (...args: Parameters<T>) => {- clearTimeout(timeoutId);+ if (timeoutId) clearTimeout(timeoutId); timeoutId = setTimeout(() => func(...args), delay); }; }Alternatively, if you need the return value, consider returning a Promise or changing the return type signature. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents | ||||||||||||||||||||||||||||||||||||||||||
| exportfunctionchunk<T>(array:T[],size:number):T[][]{ | ||||||||||||||||||||||||||||||||||||||||||
| constchunks:T[][]=[]; | ||||||||||||||||||||||||||||||||||||||||||
| for(leti=0;i<array.length;i+=size){ | ||||||||||||||||||||||||||||||||||||||||||
| chunks.push(array.slice(i,i+size)); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| returnchunks; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||