Tally Votes
Mix.install([
{:kino, github: "livebook-dev/kino", override: true},
{:kino_lab, "~> 0.1.0-dev", github: "jonatanklosko/kino_lab"},
{:vega_lite, "~> 0.1.4"},
{:kino_vega_lite, "~> 0.1.1"},
{:benchee, "~> 0.1"},
{:ecto, "~> 3.7"},
{:math, "~> 0.7.0"},
{:faker, "~> 0.17.0"},
{:utils, path: "#{__DIR__}/../utils"},
{:tested_cell, git: "https://github.com/BrooklinJazz/tested_cell"}
])
Navigation
Tally Votes
In the Elixir cell below,
-
Create a module
VoterTally
with atally/1
function. -
The
tally/1
function will accept a list of any atoms as the parameter. - The atoms represent the votes for each party.
- Return a map with the number of votes for each party.
For example:
VoterTally.tally([:pink, :indigo, :purple, :pink])
%{pink: 2, indigo: 1, purple: 1}
defmodule VoterTally do
def tally(votes) do
end
end
Utils.feedback(:voter_tally, VoterTally)
Voting Power
The system changes again to allow certain individuals/groups more
voting power. Votes will now come in as a keyword list
with the number of votes for the tally/1
function.
VoterPower.tally([dogs: 10, dogs: 20, cats: 2])
%{dogs: 30, cats: 2}
You will also need to handle keyword list within the list.
VoterPower.tally([:dogs, :dogs, :cats, dogs: 2])
%{dogs: 4, cats: 1}
defmodule VoterPower do
def tally(votes) do
end
end
Utils.feedback(:voter_power, VoterPower)
Commit Your Progress
Run the following in your command line from the project folder to track and save your progress in a Git commit.
$ git add .
$ git commit -m "finish tally votes exercise"