What's a good mathematical sets implementation in JavaScript?

前端 未结 7 1389
予麋鹿
予麋鹿 2021-02-06 16:19

Where is a good mathematical sets implementation for JavaScript? It should include efficient implementations of intersection, union, complement, and (for bonus points) the Carte

7条回答
  •  说谎
    说谎 (楼主)
    2021-02-06 16:39

    In the program that sparked this question, a set is an Array and intersect is

    s = [1,2,3];
    q = [3,4,5];
    sq = s.filter(function(x) {
        return q.indexOf(x) >= 0;
    });
    

    Of course it doesn't work in ie.

提交回复
热议问题