From f74185332385e16b1b09377b260fd7c93819649b Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 20 May 2025 15:13:36 +0200 Subject: [PATCH] compelted 1.14 --- parts/1/anecdotes/src/App.jsx | 16 ++++++++++++++++ parts/1/notes.md | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) 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 ( <>