Skip to content

Commit

Permalink
Add Utils.arrayIntersection
Browse files Browse the repository at this point in the history
  • Loading branch information
timangus committed Jul 24, 2024
1 parent ad79135 commit a6ae8b4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions source/app/ui/qml/Graphia/Utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,30 @@ function arraysMatch(a, b)
return true;
}

function* arrayIntersection(a, b)
{
let as = a.slice();
let bs = b.slice();
as.sort((x, y) => x - y);
bs.sort((x, y) => x - y);

let i = 0, j = 0;

while(i < as.length && j < bs.length)
{
if(as[i] < bs[j])
i++;
else if(as[i] > bs[j])
j++;
else
{
yield as[i];
i++;
j++;
}
}
}

function floatCompare(a, b)
{
// Note the relatively large epsilon
Expand Down

0 comments on commit a6ae8b4

Please sign in to comment.