Turf playground
by Stefano
HTML
<script src="https://npmcdn.com/@turf/turf/turf.min.js"></script>
<div id="output"></div>
JavaScript
const people = [
{
id: 0,
name: "John",
skills: ["javascript", "html", "css", "c#"]
},
{
id: 1,
name: "Brian",
skills: ["javascript", "java", "c", "c#", "c++", "html"]
},
{
id: 2,
name: "Michael",
skills: ["c", "c++", "go", "rust"]
}
];
const result = {};
people.forEach(function(person) {
person.skills.forEach(function(skill) {
if (!result[skill]) result[skill] = [];
result[skill].push(person.name);
});
});
display(result);
/* output function */
function display(data, target) {
target = target || 'output';
var el = document.getElementById(target);
// if not available create target element
if (!el) {
el = document.createElement('div');
el.setAttribute("id", target);
document.body.appendChild(el);
}
// inject text
var json = JSON.stringify(data, null, '\t');
document.getElementById(target).innerHTML = json;
}