JSFiddle - React, Tailwind, and code Playground

by godgav

HTML

<div id="result"></div>

JavaScript

var findDuplicates = function(x, y, z) {
	var xPos = 0, yPos = 0, zPos = 0;
    for(; xPos < x.length; xPos++)  {
        if (y[yPos] <= x[xPos]) {
            xIter: for(; yPos < y.length; yPos++) {
                if (z[zPos] == x[xPos]){
                    for(; zPos < z.length; zPos++) {
                        if (x[xPos] === z[zPos]) {
                            return x[xPos];
                        } else if (x[xPos] < z[zPos]) {
                            break xIter;
                        }
                    }
                }
            }
        }
    }
};

var findDuplicates2 = function(x, y, z) {
    var xInd = 0, yInd = 0, zInd = 0,
        xLen = x.length, yLen = y.length, zLen = z.length;
    
    function lessThanEqualLastIndex(n, ind, arr) {
        var i = ind, len = arr.length; 
        while ( i < len && n >= arr[i]) {
            i++;
        }
        return i > len ? -1 : i - 1;
    }
    
}

document.querySelector("#result").innerHTML = findDuplicates([2,10,20], [1,2,2,3,5,10], [2,10,30])