• + 0 comments

    My solution, const handleMostUpvoted = () => { // Logic for most upvoted articles SetArticles(prevState => [...prevState].sort((a,b) =>b.upvotes- a.upvotes)); };

    const handleMostRecent = () => { // Logic for most recent articles SetArticles(prevState => [...prevState].sort((a,b) =>new Date(b.date) - new Date(a.date))); };

    {articles && articles.map((article,index) => {
          return (
            <tbody>
              <tr data-testid="article" key= {`index-${article.title}`}>
                <td data-testid="article-title">{article.title}</td>
                <td data-testid="article-upvotes">{article.upvotes}</td>
                <td data-testid="article-date">{article.date}</td>
              </tr>
            </tbody>
          )
        })}