-
Notifications
You must be signed in to change notification settings - Fork 95
add a new functions - Remove #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,16 +224,19 @@ The letters in brackets indicate: | |
| [`Shuffle`](#shuffle) | ✓ | ✓ | ✓ | | n | Shuffle returns shuffled slice by your rand.Source | | ||
| [`Sort`](#sort) | ✓ | ✓ | | | n⋅log(n) | Sort works similar to sort.SliceType(). However, unlike sort.SliceType the slice returned will be reallocated as to not modify the input slice. | | ||
| [`SortStableUsing`](#sortstableusing) | ✓ | | ✓ | | n⋅log(n) | SortStableUsing works similar to sort.SliceStable. However, unlike sort.SliceStable the slice returned will be reallocated as to not modify the input slice. | | ||
| [`SortUsing`](#sortusing) | ✓ | | ✓ | | n⋅log(n) | SortUsing works similar to sort.Slice. However, unlike sort.Slice the slice returned will be reallocated as to not modify the input slice. | | ||
| [`Stddev`](#stddev) | | ✓ | | | n | Stddev is the standard deviation | | ||
| [`Strings`](#strings) (S) | ✓ | ✓ | ✓ | | n | Strings transforms each element to a string. | | ||
| [`SubSlice`](#subslice) | ✓ | ✓ | ✓ | | n | SubSlice will return the subSlice from start to end(excluded) | | ||
| [`Sum`](#sum) | | ✓ | | | n | Sum is the sum of all of the elements. | | ||
| [`Top`](#top) | ✓ | ✓ | ✓ | | n | Top will return n elements from head of the slice if the slice has less elements then n that'll return all elements if n < 0 it'll return empty slice. | | ||
| [`StringsUsing`](#stringsusing) | ✓ | ✓ | ✓ | | n | StringsUsing transforms each element to a string. | | ||
| [`Unique`](#unique) | ✓ | ✓ | | | n | Unique returns a new slice with all of the unique values. | | ||
| [`Unshift`](#unshift) | ✓ | ✓ | ✓ | | n | Unshift adds one or more elements to the beginning of the slice and returns the new slice. | | ||
| [`Values`](#values) | | | | ✓ | n | Values returns the values in the map. | | ||
| [`SortUsing`](#sortusing) | ✓ | | ✓ | | n⋅log(n) | SortUsing works similar to sort.Slice. However, | ||
unlike sort.Slice the slice returned will be reallocated as to not modify the input slice. | | [`Stddev`](#stddev) | ||
| | ✓ | | | n | Stddev is the standard deviation | | [`Strings`](#strings) (S) | ✓ | ✓ | ✓ | | n | Strings | ||
transforms each element to a string. | | [`SubSlice`](#subslice) | ✓ | ✓ | ✓ | | n | SubSlice will | ||
return the subSlice from start to end(excluded) | | [`Sum`](#sum) | | ✓ | | | n | Sum is the | ||
sum of all of the elements. | | [`Top`](#top) | ✓ | ✓ | ✓ | | n | Top will return n elements | ||
from head of the slice if the slice has less elements then n that'll return all elements if n < 0 it'll return empty | ||
slice. | | [`StringsUsing`](#stringsusing) | ✓ | ✓ | ✓ | | n | StringsUsing transforms each element to a string. | ||
| | [`Unique`](#unique) | ✓ | ✓ | | | n | Unique returns a new slice with all of the unique values. | ||
| | [`Unshift`](#unshift) | ✓ | ✓ | ✓ | | n | Unshift adds one or more elements to the beginning of | ||
the slice and returns the new slice. | | [`Values`](#values) | | | | ✓ | n | Values returns the | ||
values in the map. | | [`Remove`](#values) | ✓ | ✓ | | ✓ | 2n | Remove returns a new slice that does | ||
not include any of the items. | | ||
|
||
## Abs | ||
|
||
|
@@ -750,17 +753,27 @@ See AreUnique(). | |
|
||
## Unshift | ||
|
||
Unshift adds one or more elements to the beginning of the slice | ||
and returns the new slice. | ||
|
||
Unshift adds one or more elements to the beginning of the slice and returns the new slice. | ||
|
||
## Values | ||
|
||
Values returns the values in the map. | ||
|
||
|
||
Due to Go's randomization of iterating maps the order is not deterministic. | ||
|
||
## Remove | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the titles sorted. |
||
|
||
Remove returns a new slice that does not include any of the items. | ||
|
||
Usage Example: | ||
|
||
```go | ||
listA := pie.Strings{"1", "2"} | ||
listB := pie.Strings{"1", "3"} | ||
|
||
// [ "2" ] | ||
fmt.Println(listA.Remove(listB...)) | ||
``` | ||
|
||
# FAQ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ var Functions = []struct { | |
{"Unique", "unique.go", ForNumbersAndStrings, "n"}, | ||
{"Unshift", "unshift.go", ForAll, "n"}, | ||
{"Values", "values.go", ForMaps, "n"}, | ||
{"Remove", "remove.go", ForNumbersAndStrings, "2n"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. O(2n) is not a valid complexity, the constant would be removed to O(n). Also, you must keep the functions sorted. |
||
} | ||
|
||
type ElementType float64 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package functions | ||
|
||
// Remove returns a new slice that does not include any of the items. | ||
func (ss SliceType) Remove(items ...ElementType) (result SliceType) { | ||
if len(items) == 0 { | ||
return items | ||
} | ||
|
||
ss2 := make(map[ElementType]bool, len(items)) | ||
for _, item := range items { | ||
ss2[item] = true | ||
} | ||
|
||
result = SliceType{} | ||
elliotchance marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for _, v := range ss { | ||
elliotchance marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if !ss2[v] { | ||
result = append(result, v) | ||
} | ||
} | ||
return | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format of the table has been mangled. Please fix.