mirror of
https://github.com/10h30/fullstackopen.git
synced 2026-07-18 05:53:27 +09:00
completed 1.14 (anecdotes step 3)
This commit is contained in:
@@ -30,15 +30,16 @@ const App = () => {
|
|||||||
setPoints(newpoints)
|
setPoints(newpoints)
|
||||||
}
|
}
|
||||||
|
|
||||||
const Best = (props) => {
|
const BestNote = (props) => {
|
||||||
const best = props.data
|
const best = props.data
|
||||||
const mostvote = Math.max(...best)
|
const mostvote = Math.max(...best)
|
||||||
const index = best.indexOf(mostvote);
|
const index = best.indexOf(mostvote);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2>Anecdote with most votes</h2>
|
<h2>Anecdote with most votes</h2>
|
||||||
<p>{props.notes[index]}</p>
|
{mostvote >0 && <div><p>{props.notes[index]}</p>
|
||||||
<span>has {mostvote} votes</span>
|
<span>has {mostvote} votes</span></div>}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -51,8 +52,7 @@ const App = () => {
|
|||||||
<button onClick={setVote}>vote</button><button onClick={setRandom}>Next Anecdote</button>
|
<button onClick={setVote}>vote</button><button onClick={setRandom}>Next Anecdote</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Best data={points} notes={anecdotes}/>
|
<BestNote data={points} notes={anecdotes}/>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user