We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
import"h8k-components";importArticlesfrom"./components/Articles";importReact,{useState,useEffect}from'react';import"./App.css";functionApp({articles}){const[articlList,setArticleList]=useState(articles);useEffect(()=>{handleMostUpvoted();},[]);consthandleMostUpvoted=()=>{// Logic for most upvotesconsttempArr=[...articlList];tempArr.sort((a,b)=>b.upvotes-a.upvotes);setArticleList(tempArr);};consthandleMostRecent=()=>{// Logic for most recent articlesconsttempArr=[...articlList];tempArr.sort((a,b)=>newDate(b.date)-newDate(a.date));setArticleList(tempArr);};return(<><h8k-navbarheader="Sorting Articles"></h8k-navbar><divclassName="App"><divclassName="layout-row align-items-center justify-content-center my-20 navigation"><labelclassName="form-hint mb-0 text-uppercase font-weight-light">SortBy</label><buttondata-testid="most-upvoted-link"className="small"onClick={handleMostUpvoted}>MostUpvoted</button><buttondata-testid="most-recent-link"className="small"onClick={handleMostRecent}>MostRecent</button></div><ArticlesarticlList={articlList}/></div></>);}exportdefaultApp;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Article Sorting
You are viewing a single comment's thread. Return to all comments →