INNER CODE UNIT · JavaScript

getReplies

eknoorpreet/dev.to-clone · client/src/utils/index.js:35

export const getReplies = (comments, commentId) => {
  return (
    comments &&
    comments
      .filter((comment) => comment && comment.parentId === commentId)
      .sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime())
  );
};

export const formatDate = (date) => {
  const options = { year: 'numeric', month: 'short', day: 'numeric' };
  const today = new Date(date);

  return today.toLocaleDateString('en-US', options);
};

export const getRandomColor = () => {
  const letters = '0123456789ABCDEF';

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…