Sobes.tech
Senior

Compilation error # command-line-arguments ./main.go:39:32: syntax error: unexpected newline, expected { after if clause

sobes.tech AI

Answer from AI

Compilation error is related to the absence of curly braces {} after the condition in the if statement. In Go, an opening curly brace must follow the condition, even if the if body occupies a single line.

In your code:

if _, ok := set[v]; !ok
    result = append(result, v)

You need to add { and }:

if _, ok := set[v]; !ok {
    result = append(result, v)
}

Here is the corrected version of the function:

func Exclude(a, b []int) []int {
    set := make(map[int]struct{})

    for _, v := range b {
        set[v] = struct{}{}
}
    result := make([]int, 0)
    for _, v := range a {
        if _, ok := set[v]; !ok {
            result = append(result, v)
        }
    }
    return result
}
Compilation error # command-line-arguments… - sobes.tech