underscore.py
underscore.py copied to clipboard
intersection
intersection doesn't seem to perform correctly. Intersecting a simple list of strings results in [].
Simple fix was to remove the first 4 lines where there's a test for 'int', then a wrap into a tuple. Not sure what the purpose of that is for, but intersection seems to work without.
def intersection(self, *args):
"""
Produce an array that contains every item shared between all the
passed-in arrays.
"""
# if type(self.obj[0]) is int:
# a = self.obj
# else:
# a = tuple(self.obj[0])
setobj = set(self.obj)
for i, v in enumerate(args):
setobj = setobj & set(args[i])
return self._wrap(list(setobj))
confirm this