underscore.py icon indicating copy to clipboard operation
underscore.py copied to clipboard

intersection

Open stephanelsmith opened this issue 4 years ago • 1 comments

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))

stephanelsmith avatar Jun 05 '20 17:06 stephanelsmith

confirm this

Andy671 avatar Apr 02 '24 13:04 Andy671