text: import { useState } from 'react'
  
  const App = () => {
    const anecdotes = [
      'If it hurts, do it more often',
      'Adding manpower to a late software project makes it later!',
      'The first 90 percent of the code accounts for the first 10 percent of the development time...The remaining 10 percent of the code accounts for the other 90 percent of the development time.',
      'Any fool can write code that a computer can understand. Good programmers write code that humans can understand.',
      'Premature optimization is the root of all evil.',
      'Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.',
      'Programming without an extremely heavy use of console.log is same as if a doctor would refuse to use x-rays or blood tests when diagnosing patients',
    ]
  
    const [selected, setSelected] = useState(0)
    const [votes, setVotes] = useState(Array(anecdotes.length).fill(0))
    const randomIndex = Math.floor(Math.random() * anecdotes.length)
    const mostVotes = votes.reduce((prev, next) => Math.max(prev, next))
    const popularIndex = votes.indexOf(mostVotes)
  
    const vote = () =>
      setVotes((prev) => {
        const next = [...prev]
        next[selected]++
        return next
      })
  
    const handleClick = () => setSelected(randomIndex)
  
    return (
      <>
        <p>{anecdotes[selected]}</p>
        <button onClick={handleClick}>Next Anecdote</button>
        <p>This anecdote has {votes[selected]} votes</p>
        <button onClick={vote}>Vote</button>
        <h1>Most Popular Anecdote</h1>
        <p>{anecdotes[popularIndex]}</p>
        <p>This anecdote has {votes[popularIndex]} votes</p>
      </>
    )
  }
  
  export default App
  