t_sh0w

rankByProteinValue.js

Aug 30th, 2022 (edited)
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // number values -> only price is in lv, everything else is in grams
  2. const products = [
  3.   {
  4.     type: "Gainer",
  5.     brand: "Physique Nutrition",
  6.     location: "silabg",
  7.     url: "https://www.silabg.com/bg/20968-PHYSIQUE-NUTRITION-Thermo-Gainer.html",
  8.     containerRegularPrice: 118.8,
  9.     containerDiscountedPrice: 92,
  10.     containerTotalWeight: 7250,
  11.     individualServingSize: 180,
  12.     proteinInServing: 50,
  13.   },
  14.   {
  15.     type: "Low-Fat Mozzarella",
  16.     brand: "Own",
  17.     location: "Kaufland|Fantastico|Lidl",
  18.     containerRegularPrice: 2.69,
  19.     containerTotalWeight: 125,
  20.     proteinInServing: 20,
  21.   },
  22.   {
  23.     type: "Bread",
  24.     brand: "Mio 103 Grains",
  25.     location: "T-Market",
  26.     containerRegularPrice: 1.89,
  27.     containerTotalWeight: 350,
  28.     proteinInServing: 12.4,
  29.   },
  30.   {
  31.     type: "Protein Bread",
  32.     brand: "Vita",
  33.     location: "Kaufland|Fantastico|Billa",
  34.     containerRegularPrice: 3.89,
  35.     containerTotalWeight: 400,
  36.     proteinInServing: 21,
  37.   },
  38.   {
  39.     type: "Tuna Fillet in Brine",
  40.     brand: "Own Brand",
  41.     location: "Fantastico",
  42.     containerRegularPrice: 3.69,
  43.     containerTotalWeight: 110,
  44.     proteinInServing: 26.5,
  45.   },
  46.   {
  47.     type: "Lukanka of Horse & Beef",
  48.     brand: "Unitemp",
  49.     location: "Fantastico",
  50.     containerRegularPrice: 7.29,
  51.     containerTotalWeight: 220,
  52.     proteinInServing: 40,
  53.   },
  54.   {
  55.     type: "Pork Pastarma or Fillet Elena",
  56.     brand: "Budget Brand",
  57.     location: "Any Market",
  58.     containerRegularPrice: 8,
  59.     containerDiscountedPrice: 6,
  60.     containerTotalWeight: 200,
  61.     proteinInServing: 38,
  62.   },
  63.   {
  64.     type: "Low-Fat Boiled Pork Ham or Fillet",
  65.     brand: "Budget Brand",
  66.     location: "Any Market",
  67.     containerRegularPrice: 6,
  68.     containerDiscountedPrice: 5,
  69.     containerTotalWeight: 200,
  70.     proteinInServing: 18,
  71.   },
  72.   {
  73.     type: "Boiled Pork Ham",
  74.     brand: "Kazachok",
  75.     location: "Fantastico",
  76.     containerRegularPrice: 6.99,
  77.     containerTotalWeight: 350,
  78.     proteinInServing: 15,
  79.   },
  80.   {
  81.     type: "Eggs Size L",
  82.     brand: "Own Brand",
  83.     location: "Kaufland|Lidl",
  84.     containerRegularPrice: 2.4,
  85.     containerTotalWeight: 240,
  86.     individualServingSize: 60,
  87.     proteinInServing: 6.3,
  88.   },
  89.   {
  90.     type: "Beef Steak",
  91.     brand: "Restaurant's Own Brand",
  92.     location: "Fast-Food Restaurant Shtip-Shtip",
  93.     containerRegularPrice: 16,
  94.     containerTotalWeight: 200,
  95.     proteinInServing: 24,
  96.   },
  97.   {
  98.     type: "Shredded Beef",
  99.     brand: "Restaurant's Own Brand",
  100.     location: "Fast-Food Restaurant Shtip-Shtip",
  101.     containerRegularPrice: 10,
  102.     containerTotalWeight: 200,
  103.     proteinInServing: 24,
  104.   },
  105.   {
  106.     type: "Grilled Chicken Fillet",
  107.     brand: "Restaurant's Own Brand",
  108.     location: "Fast-Food Restaurant Pri Brakyata",
  109.     containerRegularPrice: 5.3,
  110.     containerTotalWeight: 180,
  111.     proteinInServing: 28,
  112.   },
  113.   {
  114.     type: "Grilled Pork Loin",
  115.     brand: "Restaurant's Own Brand",
  116.     location: "Fast-Food Restaurant Pri Brakyata",
  117.     containerRegularPrice: 5.3,
  118.     containerTotalWeight: 180,
  119.     proteinInServing: 26.76,
  120.   },
  121.   {
  122.     type: "Grilled Pork Shoulder Steak",
  123.     brand: "Restaurant's Own Brand",
  124.     location: "Fast-Food Restaurant Pri Brakyata",
  125.     containerRegularPrice: 5.3,
  126.     containerTotalWeight: 180,
  127.     proteinInServing: 25.58,
  128.   },
  129.   {
  130.     type: "Quark",
  131.     brand: "Milbona",
  132.     location: "Lidl",
  133.     containerRegularPrice: 2.69,
  134.     containerTotalWeight: 200,
  135.     proteinInServing: 12.5,
  136.   },
  137.   {
  138.     type: "Quark",
  139.     brand: "Exquisa",
  140.     location: "Kaufland|Fantastico",
  141.     containerRegularPrice: 4.99,
  142.     containerTotalWeight: 400,
  143.     proteinInServing: 10,
  144.   },
  145.   {
  146.     type: "Quark",
  147.     brand: "Danone",
  148.     location: "Kaufland|Fantastico|T-Market",
  149.     containerRegularPrice: 2.19,
  150.     containerTotalWeight: 150,
  151.     proteinInServing: 10,
  152.   },
  153.   {
  154.     type: "Skyr",
  155.     brand: "Exquisa",
  156.     location: "Kaufland|Fantastico",
  157.     containerRegularPrice: 4.99,
  158.     containerTotalWeight: 500,
  159.     proteinInServing: 8.8,
  160.   },
  161.   {
  162.     type: "Protein Bar",
  163.     brand: "Own Brand",
  164.     location: "Lidl",
  165.     containerRegularPrice: 2.49,
  166.     containerTotalWeight: 45,
  167.     individualServingSize: 45,
  168.     proteinInServing: 22.5,
  169.   },
  170.   {
  171.     type: "Protein Bar",
  172.     brand: "Chocolate & Caramel",
  173.     location: "Decathlon",
  174.     containerRegularPrice: 29.90,
  175.     containerTotalWeight: 720,
  176.     individualServingSize: 60,
  177.     proteinInServing: 22,
  178.   },
  179.   {
  180.     type: "Protein Bar",
  181.     brand: "Chocolate & Nuts",
  182.     location: "Decathlon",
  183.     containerRegularPrice: 35.90,
  184.     containerTotalWeight: 720,
  185.     individualServingSize: 60,
  186.     proteinInServing: 22,
  187.   },
  188.   {
  189.     type: "High-Protein Chips",
  190.     brand: "Own Brand",
  191.     location: "Lidl",
  192.     containerRegularPrice: 2.49,
  193.     containerTotalWeight: 40,
  194.     individualServingSize: 40,
  195.     proteinInServing: 20,
  196.   },
  197.   {
  198.     type: "High-Protein Pudding",
  199.     brand: "Milbona",
  200.     location: "Lidl",
  201.     containerRegularPrice: 2.99,
  202.     containerTotalWeight: 200,
  203.     proteinInServing: 10,
  204.   },
  205. ];
  206.  
  207. const bars = [
  208.   {
  209.     type: "Protein Bar",
  210.     brand: "FIT SPO MAXX",
  211.     location: "silabg",
  212.     containerRegularPrice: 42.13,
  213.     containerTotalWeight: 900,
  214.     individualServingSize: 75,
  215.     proteinInServing: 26,
  216.   },
  217.   {
  218.     type: "Protein Bar",
  219.     brand: "FIT SPO Power",
  220.     location: "silabg",
  221.     containerRegularPrice: 31.57,
  222.     containerTotalWeight: 660,
  223.     individualServingSize: 55,
  224.     proteinInServing: 16.5,
  225.   },
  226.   {
  227.     type: "Protein Bar",
  228.     brand: "Bezzo No Sugar",
  229.     location: "silabg",
  230.     containerRegularPrice: 29.57,
  231.     containerTotalWeight: 720,
  232.     individualServingSize: 60,
  233.     proteinInServing: 16.7,
  234.   },
  235.   {
  236.     type: "Protein Bar",
  237.     brand: "Bezzo",
  238.     location: "silabg",
  239.     containerRegularPrice: 36.85,
  240.     containerTotalWeight: 960,
  241.     individualServingSize: 80,
  242.     proteinInServing: 24,
  243.   },
  244.   {
  245.     type: "Protein Bar",
  246.     brand: "Everbuild Crisp",
  247.     location: "silabg",
  248.     containerRegularPrice: 42.24,
  249.     containerTotalWeight: 825,
  250.     individualServingSize: 55,
  251.     proteinInServing: 14.1,
  252.   },
  253.   {
  254.     type: "Protein Bar",
  255.     brand: "Own Brand",
  256.     location: "Lidl",
  257.     containerRegularPrice: 2.49,
  258.     containerTotalWeight: 45,
  259.     individualServingSize: 45,
  260.     proteinInServing: 22.5,
  261.   },
  262.   {
  263.     type: "Protein Bar",
  264.     brand: "Chocolate & Nuts",
  265.     location: "Decathlon",
  266.     containerRegularPrice: 35.90,
  267.     containerTotalWeight: 720,
  268.     individualServingSize: 60,
  269.     proteinInServing: 22,
  270.   },
  271. ];
  272.  
  273. const supplements = [
  274.   {
  275.     type: "Beef Isolate Protein Powder",
  276.     brand: "Everbuild",
  277.     location: "silabg",
  278.     url: "https://www.silabg.com/bg/21858-EVERBUILD-Ultra-Premium-100-Beef-Isolate.html",
  279.     containerRegularPrice: 104.72,
  280.     containerDiscountedPrice: 89,
  281.     containerTotalWeight: 1816,
  282.     individualServingSize: 35,
  283.     proteinInServing: 28,
  284.   },
  285.   {
  286.     type: "Whey Protein Powder",
  287.     brand: "Everbuild",
  288.     location: "silabg",
  289.     url: "https://www.silabg.com/bg/18643-EVERBUILD-Ultra-Premium-Whey-Build.html",
  290.     containerRegularPrice: 118.8,
  291.     containerDiscountedPrice: 101,
  292.     containerTotalWeight: 2271,
  293.     individualServingSize: 34,
  294.     proteinInServing: 24,
  295.   },
  296.   {
  297.     type: "Whey Protein Powder",
  298.     brand: "Optimum Nutrition Gold Standard",
  299.     location: "silabg",
  300.     url: "https://www.silabg.com/bg/176-OPTIMUM-NUTRITION-100-Whey-Gold-Standard.html",
  301.     containerRegularPrice: 138,
  302.     containerTotalWeight: 2272,
  303.     individualServingSize: 30.4,
  304.     proteinInServing: 24,
  305.   },
  306.   {
  307.     type: "Whey Protein Powder",
  308.     brand: "Amix Pure Fusion",
  309.     location: "silabg",
  310.     url: "https://www.silabg.com/bg/11568-AMIX-Whey-Pure-Fusion.html",
  311.     containerRegularPrice: 136.4,
  312.     containerTotalWeight: 2300,
  313.     individualServingSize: 35,
  314.     proteinInServing: 26.25,
  315.   },
  316.   {
  317.     type: "Whey Isolate Protein Powder",
  318.     brand: "Domyos",
  319.     location: "Decathlon",
  320.     url: "https://www.decathlon.bg/p/324917-130370_protein-izolat-whey-22-g-shokolad.html",
  321.     containerRegularPrice: 129,
  322.     containerTotalWeight: 2200,
  323.     individualServingSize: 30,
  324.     proteinInServing: 24,
  325.   },
  326.   {
  327.     type: "Whey Protein Powder",
  328.     brand: "My Protein",
  329.     location: "myprotein",
  330.     url: "https://www.myprotein.bg/sports-nutrition/limited-edition-impact-whey-protein/13470318.html",
  331.     containerRegularPrice: 164.99,
  332.     containerDiscountedPrice: 112,
  333.     containerTotalWeight: 2500,
  334.     individualServingSize: 25,
  335.     proteinInServing: 20.5,
  336.   },
  337.   {
  338.     type: "Whey Protein Powder",
  339.     brand: "Strong Energy",
  340.     location: "stanimiretov",
  341.     url: "https://stanimiretov.com/protein",
  342.     containerRegularPrice: 109,
  343.     containerTotalWeight: 2100,
  344.     individualServingSize: 30,
  345.     proteinInServing: 20,
  346.   },
  347.   {
  348.     type: "Whey Isolate Protein Powder",
  349.     brand: "FA Nutrition Gold",
  350.     location: "readyforlife",
  351.     url: "https://readyforlife.bg/asortiment/3790-14707-fa-nutrition-gold-whey-isolate.html",
  352.     containerRegularPrice: 199.95,
  353.     containerDiscountedPrice: 139.97,
  354.     containerTotalWeight: 2270,
  355.     individualServingSize: 30,
  356.     proteinInServing: 25,
  357.   },
  358.   {
  359.     type: "Whey Hydrolysed Protein Powder",
  360.     brand: "Dorian Yates Nutrition",
  361.     location: "readyforlife",
  362.     url: "https://readyforlife.bg/asortiment/7690-24879-dorian-yates-nutrition-shadowhey-hydrolysate-protein.html",
  363.     containerRegularPrice: 219.95,
  364.     containerDiscountedPrice: 153.97,
  365.     containerTotalWeight: 2270,
  366.     individualServingSize: 25,
  367.     proteinInServing: 22,
  368.   },
  369.   {
  370.     type: "Whey Isolate Protein Powder",
  371.     brand: "Kevin Levrone",
  372.     location: "readyforlife",
  373.     url: "https://readyforlife.bg/asortiment/4178-6934-kevin-levrone-levroiso-whey.html",
  374.     containerRegularPrice: 185.95,
  375.     containerDiscountedPrice: 129.95,
  376.     containerTotalWeight: 2000,
  377.     individualServingSize: 35,
  378.     proteinInServing: 29.8,
  379.   },
  380.   {
  381.     type: "Whey Isolate Protein Powder",
  382.     brand: "FA Nutrition CORE",
  383.     location: "readyforlife",
  384.     url: "https://readyforlife.bg/asortiment/7700-24931-fa-nutrition-core-iso.html",
  385.     containerRegularPrice: 144.95,
  386.     containerDiscountedPrice: 114.51,
  387.     containerTotalWeight: 2000,
  388.     individualServingSize: 30,
  389.     proteinInServing: 25,
  390.   },
  391.   {
  392.     type: "Whey Isolate Protein Powder",
  393.     brand: "Scitec",
  394.     location: "readyforlife",
  395.     url: "https://readyforlife.bg/asortiment/3025-13721-scitec-100-whey-isolate.html",
  396.     containerRegularPrice: 108,
  397.     // containerDiscountedPrice: 108,
  398.     containerTotalWeight: 2000,
  399.     individualServingSize: 25,
  400.     proteinInServing: 19,
  401.   },
  402.   {
  403.     type: "Whey Protein Powder",
  404.     brand: "BSN DNA",
  405.     location: "readyforlife",
  406.     url: "https://readyforlife.bg/asortiment/4265-14962-bsn-dna-whey.html",
  407.     containerRegularPrice: 138,
  408.     containerDiscountedPrice: 78.49,
  409.     containerTotalWeight: 1800,
  410.     individualServingSize: 30,
  411.     proteinInServing: 24,
  412.   },
  413.   {
  414.     type: "Beef Isolate Protein Powder",
  415.     brand: "MuscleTech Platinum",
  416.     location: "readyforlife",
  417.     url: "https://readyforlife.bg/asortiment/4268-14975-muscletech-platinum-beef-protein.html",
  418.     containerRegularPrice: 135,
  419.     containerDiscountedPrice: 98.55,
  420.     containerTotalWeight: 1970,
  421.     individualServingSize: 40,
  422.     proteinInServing: 34,
  423.   },
  424.   {
  425.     type: "Whey Protein Powder",
  426.     brand: "Universal Ultra Pro",
  427.     location: "readyforlife",
  428.     url: "https://readyforlife.bg/asortiment/3170-14002-universal-ultra-whey-pro.html",
  429.     containerRegularPrice: 145,
  430.     containerDiscountedPrice: 123,
  431.     containerTotalWeight: 2268,
  432.     individualServingSize: 30,
  433.     proteinInServing: 22,
  434.   },
  435.   {
  436.     type: "Whey Protein Powder",
  437.     brand: "Sportness",
  438.     location: "dm",
  439.     url: "https://www.dm-drogeriemarkt.bg/sportness-surovatachen-protein-na-prah-s-vkus-na-vanilia-p4058172511110.html",
  440.     containerRegularPrice: 22.4,
  441.     // containerDiscountedPrice: 22.4,
  442.     containerTotalWeight: 450,
  443.     individualServingSize: 100,
  444.     proteinInServing: 80,
  445.   },
  446. ];
  447.  
  448. const regularServingSize = 100;
  449. const proteinFactor = 10;
  450.  
  451. const ranking = bars
  452.   // const ranking = products
  453.   // const ranking = supplements
  454.   .map((item) => {
  455.     const {
  456.       containerRegularPrice,
  457.       containerDiscountedPrice,
  458.       containerTotalWeight,
  459.       individualServingSize,
  460.       proteinInServing,
  461.     } = item;
  462.  
  463.     const containerPrice = containerDiscountedPrice || containerRegularPrice;
  464.     const servingSize = individualServingSize || regularServingSize;
  465.     const servings = containerTotalWeight / servingSize;
  466.     const containerProteinWeight = servings * proteinInServing;
  467.  
  468.     item.pricePerTenGrammsOfProtein =
  469.       (containerPrice / containerProteinWeight) * proteinFactor;
  470.  
  471.     return item;
  472.   })
  473.   .sort((a, b) => a.pricePerTenGrammsOfProtein - b.pricePerTenGrammsOfProtein)
  474.   .map(({ type, brand, location, pricePerTenGrammsOfProtein }, i) => {
  475.     return `${i + 1
  476.       }. ${type} - ${brand}, ${location} -> ${pricePerTenGrammsOfProtein.toFixed(
  477.         2
  478.       )}lv`;
  479.   })
  480.   .join("\n");
  481.  
  482. console.log(
  483.   `Protein sources by price per ${proteinFactor}g of protein: \n${ranking}`
  484. );
  485.  
Advertisement
Add Comment
Please, Sign In to add comment