Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
792 B
28
Indexable
// const finalList = myFilter.reduce ((a,c) => {
  //   if(c.category !== a.lastCategory){
  //     a.output = [...a.output,<ProductCategoryRow key={c.category} category={c.category}/>]
  //     a.lastCategory = c.category
  //   }
  //   a.output = [...a.output,<ProductRow key={c.name} product={c}/>]
  //   return a
  // },{lastCategory:null,output: []})

  // console.log(finalList)


  //ฉบับสายย่อ
  const finalList = myFilter.reduce((a, c) => {
    if (c.category !== a.lastCategory) 
    a.output.push(<ProductCategoryRow key={c.category} category={c.category} />);
    a.output.push(<ProductRow key={c.name} product={c} />);
    a.lastCategory = c.category;
    return a;
  }, { lastCategory: null, output: [] });
  
  console.log(finalList);
Leave a Comment