-
Notifications
You must be signed in to change notification settings - Fork 0
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
Added outersection functions for Int. #12
Conversation
slicex/int.go
Outdated
|
||
// IntOuterRight returns right outersection of 2 slices. | ||
func IntOuterRight(slice1, slice2 []int) []int { |
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.
isn't this exactly the same as InOuterLeft, but with arguments order reversed? If so, why not call InOuterLeft(slice2, slice1)?
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.
Right, fixed
slicex/int.go
Outdated
|
||
// IntOuter returns outersection of 2 slices. | ||
func IntOuter(slice1, slice2 []int) []int { |
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.
I get that you wanted to achieve this: https://en.wikipedia.org/wiki/Symmetric_difference
you could put that link to comment somewhere here
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.
Yeah, changed naming as well :).
// IntOuter returns outersection of 2 slices. | ||
func IntOuter(slice1, slice2 []int) []int { | ||
checks := make(map[int]int8, len(slice1)+len(slice2)) |
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.
if you want to avoid a map, then you could sort joined slices and then look if consecutive values are repeating, e.g. for one of the test cases:
1,2,3,3,4,5
pros: not using map
con: sort operation, which is also not free
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.
Minus of this approach is reiterating for repetitions, in current approach there are 3 fors.
- 1st slice
- 2nd slice
- map to find out difference.
Map is very useful in these cases to find out if value is existing or find out counts.
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.
there would be only one sort and one for, but it's not that important
No description provided.