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

var data = [
        { product: "botijão 13KG", quantity: "10", totalPurchased: "220,00", totalDiscounts: "200,00" },
        { product: "botijão 13KG", quantity: "4", totalPurchased: "208,00", totalDiscounts: "0,00" },
        { product: "botijão 13KG", quantity: "13", totalPurchased: "666,00", totalDiscounts: "10,00" }
    ];

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

            // 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;
                    
                     
                     totalOfPurchasedNested = totalOfPurchasedNested.replace(/\./g, "").replace(",", ".");

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

                    // Push Group With Received JSON In Native Array
         ...