JSFiddle - React, Tailwind, and code Playground

by Christopher Stephens

HTML

<h1>
Code Sample
</h1>
<h2>
Results
</h2>
<div id="results">

</div>

JavaScript

const print = (toPrint) => {
	const line =  document.createElement('pre');
  line.textContent = JSON.stringify(toPrint,null, 2);
	document.getElementById('results').appendChild(line);
}
console.log = print;

// RESEARCH ON THIS TYPE OF DATA
// What is IOC? Indicator of compromise or IOC is a forensic term that refers to the evidence on a device that points out to a security breach

// example json object 
const intelligence = [
    {
        ioc: "1.2.3.4",
        threat: "low",
        countryCode: "us",
        seenBy: ["usSS", "whiteHatsAnon"],
        lastSeen: 1650309845083
    },{
        ioc: "1.2.3.5",
        threat: "high",
        countryCode: "us",
        seenBy: ["usSS"],
        lastSeen: 1650307825088
    },{
        ioc: "gougle.com",
        threat: "high",
        regionName: "utah",
        countryCode: "ca",
        seenBy: ["usSS", "whiteHatsAnon", "ruWatch", "privateInc", "angiesList"],
        lastSeen: 1650609845087
    },{
        ioc: "goople.com",
        threat: "high",
        countryCode: "ru",
        seenBy: ["usSS", "whiteHatsAnon", "angiesList"],
        lastSeen: 1650109815283
    },
];

// intialize data 
const data = {};

// get the elements in the json 
elements = Object.keys(intelligence[0])

// adds the keys to the object
elements.forEach((i) => {
    data[i] = {};
});


// counts all the types of variables for each key 
intelligence.forEach((el) => {
    elements.forEach((key) => {
        if (key == 'lastSeen') {
            var date = new Date(el[key] * 1000);
            el[key] = date.toUTCString();
        }
        //if the object is not a object type
        if (typeof el[key] != "object") {
            // if the element hasn't shown up before
            if(data[key][el[key]] == "undefined"){
                data[key][el[key]] = 1;
            }
            // adds to existing element 
            else {
                data[key][el[key]] = data[key][el[key]] ? (data[key][el[key]] += 1) : 1
            }
       ...