Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Task 1 — Collection Equality

Objective

Create a function that determines whether three integer slices contain the same values regardless of their ordering.

The function must return a boolean result.

Input

Create three integer slices.

List 1

list1 := []int{
    41, 26, 74, 25, 85, 36,
    93, 47, 56, 76, 20, 39,
}

List 2

list2 := []int{
    39, 25, 47, 76, 56, 85,
    93, 26, 36, 41, 74, 20,
}

List 3

list3 := []int{
    25, 39, 47, 85, 56, 76,
    41, 74, 20, 93, 36, 26,
}

Function

Create a function named:

CheckEquality(...)

The function receives all three slices and returns:

bool

Requirements

The function must determine whether all three collections contain the same elements.

The order of the values must not affect the result.

For example:

{1, 2, 3}

and:

{3, 1, 2}

contain the same values even though their ordering is different.

Expected Result

For the provided input:

CheckEquality(list1, list2, list3)

the result should be:

true

because all three slices contain the same integer values.

Duplicate Values

A complete implementation should compare the actual contents of the collections, including duplicate counts.

For example:

{1, 1, 2}

should not be considered equal to:

{1, 2, 2}

even though both collections contain the distinct values 1 and 2.

Therefore, equality should mean that every value occurs the same number of times in every input collection.

Length Validation

If the slices have different lengths, they cannot contain exactly the same collection of elements.

The function may therefore immediately return:

false

when:

len(list1) != len(list2)

or:

len(list1) != len(list3)

Implementation Notes

The implementation should not depend on the original ordering of the slices.

Possible strategies include:

  • sorting copies of the collections and comparing them
  • counting occurrences of each value
  • using another structure that preserves occurrence counts

The original input slices should not need to be permanently reordered unless the implementation explicitly allows mutation.

Scalionix Docs

Keyboard Shortcuts

Navigate the documentation without leaving the keyboard.
Navigation
Previous subject
←
Next subject
→
Previous subsection
Alt + ↑
Next subsection
Alt + ↓
Interface
Documentation Home
Ctrl + Enter
Search
Alt + Q
Open shortcuts
?
Close dialog
Esc
Scalionix Docs

Search Documentation