diff --git a/parts/1/anecdotes/src/App.jsx b/parts/1/anecdotes/src/App.jsx index f4892ea..a7eff9c 100644 --- a/parts/1/anecdotes/src/App.jsx +++ b/parts/1/anecdotes/src/App.jsx @@ -30,11 +30,27 @@ const App = (props) => { setSelected(Math.floor(Math.random() * props.anecdotes.length)) } + const getMostVotedIndex = (votesArray) => { + let highestVoteCount = 0; + let highestVoteIndex; + for (let i = 0; i < votesArray.length; i++) { + if (votesArray[i] >= highestVoteCount) { + highestVoteIndex = i + highestVoteCount = votesArray[i] + } + } + + return highestVoteIndex; + } + return ( <>