Answers for "intersection in javascript"

10

javascript do arrays intersect

let intersection = arrA.filter(x => arrB.includes(x));
Posted by: Guest on March-31-2020
1

js find intersection point

function line_intersect(x1, y1, x2, y2, x3, y3, x4, y4)
{
    var ua, ub, denom = (y4 - y3)*(x2 - x1) - (x4 - x3)*(y2 - y1);
    if (denom == 0) {
        return null;
    }
    ua = ((x4 - x3)*(y1 - y3) - (y4 - y3)*(x1 - x3))/denom;
    ub = ((x2 - x1)*(y1 - y3) - (y2 - y1)*(x1 - x3))/denom;
    return {
        x: x1 + ua * (x2 - x1),
        y: y1 + ua * (y2 - y1),
        seg1: ua >= 0 && ua <= 1,
        seg2: ub >= 0 && ub <= 1
    };
}
Posted by: Guest on July-30-2020
0

javascript get intersection of two arrays

function getArraysIntersection(a1,a2){
    return  a1.filter(function(n) { return a2.indexOf(n) !== -1;});
}
var colors1 = ["red","blue","green"];
var colors2 = ["red","yellow","blue"];
var intersectingColors=getArraysIntersection(colors1, colors2); //["red", "blue"]
Posted by: Guest on August-01-2019
0

intersection and difference in javascript

const intersection = new Set(Array.from(set1).filter(x => set2.has(x)));
const difference = new Set(Array.from(set1).filter(x => !set2.has(x)));
Posted by: Guest on August-04-2021

Code answers related to "intersection in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language