underscore/docs/content/collections/partition.md
Ruidy d19fa7b8c9
docsite (#19)
* change documentation theme and structure

* add config files

* fix links

* add build doc command

Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-23 10:32:56 -04:00

508 B

title date
Partition 2022-03-21T13:33:23-04:00

Partition splits the slice into two slices: one whose elements all satisfy predicate and one whose elements all do not satisfy predicate.

package main

import (
	"fmt"
	u "github.com/rjNemo/underscore"
)

func main() {
	nums := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	isEven := func(n int) bool { return n%2 == 0 }

	evens, odds := u.Partition(nums, isEven)
	fmt.Println(evens) // {0, 2, 4, 6, 8}
	fmt.Println(odds)  // {1, 3, 5, 7, 9}
}