JSFiddle - React, Tailwind, and code Playground

JavaScript

var Bayes = Class.create();
Bayes.prototype = {
    initialize: function() {
    },

    learn: function (data, category, features, weight = 1) {
     var pathCategory = pathCategory(category);
     if (data.containsKey(pathCategory)) {
         data.put(pathCategory, data.get(pathCategory) + weight);
     } else {
         data.put(pathCategory);
         data.put(pathGlobalCountCategories(), (data.containsKey(pathGlobalCountCategories)) ? data.get(pathGlobalCountCategories()) + 1: 1);
     }
     for ( var feature in features) {
         var pathFeatureKey = pathFeatureKey(feature.getKey());
         data.put(pathFeatureKey, (data.containsKey(pathFeatureKey)) ? data.get(pathFeatureKey) + weight : weight);
         var pathCategoryFeatureKeyValue = pathCategoryFeatureKeyValue(category, feature.getKey(), feature.getValue());
         var pathFeatureKeyValue = pathFeatureKeyValue(feature.getKey(), feature.getValue());
         if (data.containsKey(pathFeatureKeyValue)) {
         		data.put(pathFeatureKeyValue, data.get(pathFeatureKeyValue) + weight);
         } else {
         		data.put(pathFeatureKeyValue, weight);
            var pathFeatureKeyCountValueTypes = pathFeatureKeyCountValueTypes(feature.getKey());
            data.put(pathFeatureKeyCountValueTypes, (data.containsKey(pathFeatureKeyCountValueTypes) ? data.get(pathFeatureKeyCountValueTypes) + 1 : 1));
         }
         data.put(pathCategoryFeatureKeyValue, (data.containsKey(pathCategoryFeatureKeyValue) ? data.get(pathCategoryFeatureKeyValue) + weight : weight));
     }
    },

    classify: function (features, explainData, alpha = 1.0, variant = false) {
     explanation = {};
     var globalCount = data.containsKey(pathGlobal()) ? data.get(pathGlobal()) : 0;
     if (explainData) { explanation.put(pathGlobal(), globalCount); }
     var globalCountCategories = (data.containsKey(pathGlobalCountCategories) ? data.get(pathGlobalCountCategories) : 0);
     if (explainData) {...