zcash-grant-system/frontend/client/utils/helpers.ts

28 lines
631 B
TypeScript
Raw Normal View History

2018-10-04 21:27:02 -07:00
import { Comment } from 'types';
2018-09-10 09:55:26 -07:00
export function isNumeric(n: any) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
export async function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export function findComment(
commentId: Comment['commentId'],
comments: Comment[],
): Comment | null {
for (const comment of comments) {
if (comment.commentId === commentId) {
return comment;
} else if (comment.replies.length) {
const foundComment = findComment(commentId, comment.replies);
if (foundComment) {
return foundComment;
}
}
}
return null;
}