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 3 — Common Values

Objective

Create a function that finds all integer values that exist in each of three input slices.

The function must return the values common to all three collections.

Input

List 1

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

List 2

list2 := []int{
    39, 43, 51, 26, 73, 46,
    58, 93, 75, 68, 38, 85,
}

List 3

list3 := []int{
    93, 26, 70, 29, 85, 36,
    80, 79, 50, 42, 20, 39,
}

Function

Create a function named:

TakeCommonValue(...)

The function receives:

[]int
[]int
[]int

and returns:

[]int

Requirements

A value belongs in the result only if it appears in:

list1
AND
list2
AND
list3

Values appearing in only one or two collections must not be returned.

Common Values

For the provided input, the values common to all three slices are:

26
85
93
39

Expected Result

[]int{
    26,
    85,
    93,
    39,
}

Duplicate Handling

The result should contain each common numeric value only once.

If a value occurs multiple times inside one or more input slices, that should not cause the value to be repeated in the result.

For example:

list1 = {5, 5, 5}
list2 = {5, 5}
list3 = {5}

should produce:

[]int{5}

Result Ordering

The original task defines the expected result as:

[]int{26, 85, 93, 39}

but does not explicitly define a general ordering rule.

A deterministic implementation should choose and document an ordering rule.

One reasonable option is to preserve the order in which common values appear in the first input slice.

Alternatively, the result may be sorted if the specification is intentionally extended to require sorted output.

Implementation Notes

This task represents the intersection of three integer collections.

The implementation should avoid unnecessary repeated scans when working with larger inputs.

The exact algorithm is left to the developer.

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