DEV Community

Discussion on: Daily Coding Puzzles - Oct 29th - Nov 2nd

Collapse
 
thejessleigh profile image
jess unrein

Idk that this is an actual good Go solution - I'm not a Go expert so it can be hard for me to tell sometimes. It's so idiomatically verbose!

func Count(a []int) (r []int) {
    r = make([]int, 0)

    if len(a) == 0 {
        return
    }

    var pos int = 0
    var neg int = 0

    for _, item := range a {
        if item >= 0 {
            pos += 1
        } else {
            neg += item
        }
    }

    r = append(r, pos)
    return append(r, neg)
}