Skip to content
loading...

re: Daily Challenge #187 - Most Sales VIEW POST

FULL DISCUSSION
 

Javascript - Reduce method

const products = [
  "Cell Phones",
  "Vacuum Cleaner",
  "Computer",
  "Autos",
  "Gold",
  "Fishing Rods",
  "Lego",
  " Speakers"
];
const amounts = [0, 12, 24, 17, 19, 23, 120, 8];
const prices = [9, 24, 29, 31, 51, 8, 120, 14];

const { productName } = products.reduce(
  (acc, val, i) =>
    amounts[i] * prices[i] > acc.value
      ? {
          productName: val,
          value: amounts[i] * prices[i]
        }
      : acc,
  { productName: "", value: 0 }
);

console.log(productName);
code of conduct - report abuse