Skip to content

Latest commit

 

History

History
executable file
·
245 lines (165 loc) · 4.04 KB

electionday-doc.md

File metadata and controls

executable file
·
245 lines (165 loc) · 4.04 KB

electionday

import "electionday"

Index

func DecrementVotesOfCandidate(results map[string]int, candidate string)

DecrementVotesOfCandidate decrements by one the vote count of a candidate in a map

Example

{
	var finalResults = map[string]int{
		"Mary": 10,
		"John": 51,
	}

	DecrementVotesOfCandidate(finalResults, "Mary")

	fmt.Println(finalResults["Mary"])

}

Output

9

func DisplayResult(result *ElectionResult) string

DisplayResult creates a message with the result to be displayed

Example

{
	var result *ElectionResult

	result = &ElectionResult{
		Name:  "John",
		Votes: 32,
	}

	message := DisplayResult(result)

	fmt.Println(message)

}

Output

John (32)

func IncrementVoteCount(counter *int, increment int)

IncrementVoteCount increments the value in a vote counter

Example

{
	var votes int
	var voteCounter *int

	votes = 3
	voteCounter = &votes

	IncrementVoteCount(voteCounter, 2)

	fmt.Println(votes == 5)
	fmt.Println(*voteCounter == 5)

}

Output

true
true

func NewVoteCounter(initialVotes int) *int

NewVoteCounter returns a new vote counter with a given number of initial votes.

Example

{
	var initialVotes int
	var counter *int

	initialVotes = 2
	counter = NewVoteCounter(initialVotes)

	fmt.Println(*counter == initialVotes)

}

Output

true

func VoteCount(counter *int) int

VoteCount extracts the number of votes from a counter.

Example

{
	var votes int
	votes = 3

	var voteCounter *int
	voteCounter = &votes

	var nilVoteCounter *int

	fmt.Println(VoteCount(voteCounter))
	fmt.Println(VoteCount(nilVoteCounter))

}

Output

3
0

ElectionResult represents an election result.

type ElectionResult struct {
    // Name is the name of the candidate.
    Name string
    // Number is the total number of votes the candidate had.
    Votes int
}
func NewElectionResult(candidateName string, votes int) *ElectionResult

NewElectionResult creates a new election result

Example

{
	var result *ElectionResult

	result = NewElectionResult("Peter", 3)

	fmt.Println(result.Name == "Peter")
	fmt.Println(result.Votes == 3)

}

Output

true
true

Generated by gomarkdoc