JSFiddle - React, Tailwind, and code Playground

by grundez

HTML

<div id="test">d</div>

JavaScript

var theArray = [
  [126, 131, 138, 139, 140, 143],
  [126, 201]
];

function intersect(theArray){
    var result = [];
    for(var i = 0; i < theArray.length; i++){
        var row = [];
        $.each(theArray[i], function(index, value){
            var nextArray = (i+1 < theArray.length
                             ?theArray[i+1]:theArray[0]);
            if($.inArray(value, nextArray) != -1) {
                row.push(theArray[i][index]);    
            }
        }); 
        result.push(row);
    }
    return result;
}
               
var res = intersect(theArray);
document.getElementById("test").innerHTML = JSON.stringify(res);