iNaturalist: record the encounter, then identify it together
iNaturalist lets people record plants and animals they encounter and ask the community to identify them. Photos, time, place and different judgments stay with the observation, so its name can become more precise without hiding disagreement.
Break down the problem and try your own design and implementation first. Then explore the reasoning to check states, edge cases, trade-offs, and ways to test your approach. The guide offers a reasoning path, not a complete implementation.
Count current identifications without counting old opinions
Implement a “current judgment” module for a community photo-organizing tool. A photograph may show Park A or Park B. Each participant can change or withdraw their judgment. The page needs the current number of supporters for each option, without counting opinions a person has replaced.
- Start with no judgments. Provide three operations: submit someone’s A or B judgment, withdraw someone’s judgment, and query the current counts. A submission replaces that person’s previous judgment. Withdrawing an absent person changes nothing. A query returns {A:count,B:count,total:active participant count}. Names are nonempty and options are valid; operations occur sequentially. A caller changing a query result must not change the module’s internal records.
- After Jia chooses A and Yi chooses A, return {A:2,B:0,total:2}. After Jia switches to B, return {A:1,B:1,total:2}. Jia choosing B again changes nothing. Withdrawing Yi produces {A:0,B:1,total:1}; withdrawing Yi again leaves it unchanged.
- Deliver a runnable small module and these call results. Explain what you store as facts, what you calculate from them and how this arrangement prevents support counts from accumulating after a change. Handle local data for one photograph only.
Explore the reasoning
- Decide what identifies an active judgment. Consider using current judgments as the basis, or also maintaining a set of counts.
- When Jia changes from A to B, check that the old support disappears while the total remains two. Compare what each storage approach must keep synchronized.
- Use repeated submission, repeated withdrawal and caller modification of a query result to check whether external operations can corrupt the internal records.