JSFiddle - React, Tailwind, and code Playground

by Gabriel Correa

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/linq.js/2.2.0.2/linq.min.js"></script>

JavaScript

$.ajax({
        type: "GET",
        dataType: "JSON",
        url: 'https://famagas-api.herokuapp.com/api/itapeCompanyNews',
        success: function (allResponseTwo) {
            // Native Array
            var receivedDataOne = [];

            // Group Received JSON By Total Of Purchased
            for (var i = 0; i < allResponseTwo.length; i++) {
                // Group Received JSON By Total Of Purchased
                var totalOfPurchased = allResponseTwo[i].purchase_history;
                for (var j = 0; j < totalOfPurchased.length; j++) {
                    // Declare Variables Containing Extend Details
                    var purchasedProductNested = totalOfPurchased[j].purchasedProduct;
                    var quantityOfPurchasedNested = totalOfPurchased[j].quantityPurchased;
                    var totalOfPurchasedNested = totalOfPurchased[j].totalOfPurchased;
                    var totalOfDiscountsPurchasedNested = totalOfPurchased[j].discountsToConsider;

                    // Format The Money So That It Is Possible To Count
                    totalOfPurchasedNested = totalOfPurchasedNested.replace(/\./g, "").replace(",", ".");
                    totalOfDiscountsPurchasedNested = totalOfDiscountsPurchasedNested.replace(/\./g, "").replace(",", ".");

                    // Final JSON Array Containing Extend Details
                    var allResponseTwoWithExtendDetails = {
                        product: purchasedProductNested,
                        quantity: quantityOfPurchasedNested,
                        totalPurchased: JSON.parse(totalOfPurchasedNested),
                        totalDiscounts: totalOfDiscountsPurchasedNested
                    };

                    // Push Group With Received JSON In Native Array
                    receivedDataOne.push(allResponseTwoWithExtendDetails);
                }
            }

            console.log(receivedDataOne);

            // Group And Count By Best Seller Produtc
          ...