test

mail@pastecode.io avatar
unknown
javascript
3 years ago
711 B
1
Indexable
Never
products.forEach((product) => {
  filters.forEach((filter) => {
    const newFilter = newFilters.find(f => f.name === filter.name);
    if(newFilter) {
      if(!newFilter.availableFilters.includes(product[filter.name])) {
        newFilter.availableFilters.push(product[filter.name]);
      }
    } else {
      // clear filter object
      const foundFilter = filters.find((f) => f.name === filter.name);
      if(foundFilter) {
        newFilters.push({
          name: foundFilter.name,
          title: foundFilter.title,
          availableFilters: [product[filter.name]],
          _id: foundFilter._id,
          objectType: foundFilter.objectType
        });
      }
    }
  });
})