Javascript algorithm to find elements in array that are not in another array

前端 未结 8 1100
情歌与酒
情歌与酒 2020-11-27 06:19

I\'m looking for a good algorithm to get all the elements in one array that are not elements in another array. So given these arrays:

var x = [\"a\",\"b\",\         


        
8条回答
  •  醉话见心
    2020-11-27 07:13

    Here's an alternative using underscore.js:

    function inAButNotInB(A, B) {
      return _.filter(A, function (a) {
        return !_.contains(B, a);
      });
    }
    

提交回复
热议问题