Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Chrome 52
Mac OS X 10.11.6
Other
8 years ago
Test name Executions per second
Best 61282800.0 Ops/sec
Mine 65765808.0 Ops/sec
Script Preparation code:
AخA
 
var a = [1,2,2,2,3,4,5,6,8,4,5,8,4,6,3,5];
var b = [2,4];
Tests:
  • Best

     
    function array_diff(a, b) {
      return a.filter(function(x) { return b.indexOf(x) == -1; });
    }
  • Mine

     
    function array_diff(a, b) {
     let arrStr =  a.join('');
     b.forEach(function(item) {
       arrStr = arrStr.replace(new RegExp(item, 'g'), '');
     });
     
     return arrStr.split('').map(function(t){return parseInt(t)});
    }