JSFiddle - React, Tailwind, and code Playground
by turiyag
HTML
<html>
<head>
</head>
<body>
<div id="console">
<h2>Console</h2>
</div>
</body>
</html
CSS
div {
border: 1px solid black;
}
h2 {
font-size: 2em;
}
JavaScript
var data = [
[
{"name":"product1","light":"1"},
{"name":"product2","light":"2"},
{"name":"product5","light":"5"},
{"name":"product4","light":"4"}
],
[
{"name":"product2","light":"2"},
{"name":"product3","light":"3"},
{"name":"product4","light":"4"}
]
];
$(function() {
var intersection = valueIntersect(data[0],data[1]);
for (o in intersection) {
$("#console").append("<p>Name: " + intersection[o].name + ", Light: " + intersection[o].light + "</p>");
}
});
function valueIntersect(a1, a2) {
var aReturn = [];
for(i1 in a1) {
o1 = a1[i1];
for (i2 in a2) {
o2 = a2[i2];
if(equals(o1,o2)) {
aReturn.push(o1);
break;
}
}
}
return aReturn;
}
function equals(o1, o2) {
if (!o2 || o1.length != o2.length) {
return false;
}
for (i in o1) {
if (o1[i] !== o2[i]) {
return false;
}
}
return true;
};