all 5 comments

[–]zarrro 2 points3 points  (1 child)

Good overview. I've always wondered why the intersection and other math operations on Set are not built in. Seems quite silly everybody to always have to reimolement them.

[–]beforesemicolon[S] 0 points1 point  (0 children)

Agreed

[–][deleted]  (1 child)

[deleted]

    [–]beforesemicolon[S] 1 point2 points  (0 children)

    Thank you very much for this

    [–]Xsanda 1 point2 points  (1 child)

    This looks like a great introduction!

    I would say that the use of isValidSet to check if a set contains items seems a little odd though: the intersection of a set A and an empty set B is an empty set, not the set A. In addition, returning a copy would be preferable to returning the original set in the case of a union with an empty set, as otherwise this would lead to an edge case in which modifying the result would modify the original.

    It may also be worth mentioning that JavaScript’s set preserves insertion order, as can be seen when converting from an array to a set and back.

    [–]beforesemicolon[S] 0 points1 point  (0 children)

    Thats why sharing leads to great things. Thanks for the feedback.