Skip to content

Commit

Permalink
fix reduce method crashing with no favs
Browse files Browse the repository at this point in the history
  • Loading branch information
HectorVilas committed May 2, 2023
1 parent 4198c6a commit fe02af8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/storedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ export const storedData = (() => {
function getCounts() {
let cartCount = 0;
let favsCount = 0;

for (const item in storedCart) {
cartCount += storedCart[item];
}
favsCount = storedFavs.reduce((curr, next) => curr + next);

favsCount = storedFavs.length > 0 ? storedFavs.reduce((curr, next) => curr + next) : 0;

return {
cartCount,
Expand Down

0 comments on commit fe02af8

Please sign in to comment.