Last active
April 1, 2022 15:40
-
-
Save Andaeiii/51cc65999eda675edaf68d6baa4cefa1 to your computer and use it in GitHub Desktop.
compute the json object of each item in the shopping cart using the Ids
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const computeStats = () => { | |
if (cart.items.length !== 0) { | |
var ids = cart.items.map(item => item.id); | |
let isUnique = (value, index, self) => self.indexOf(value) === index; | |
let distinct = ids.filter(isUnique); | |
distinct.forEach(id => { | |
stats.push({ | |
"id": id, | |
'count': cart.items.filter(o => o.id === id).length, | |
'clicked': (id === curId) ? 'true' : 'false' | |
}); | |
}); | |
} | |
return stats.sort((a, b) => b.count - a.count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I modelled a shopping application, and in building the shopping cart,
i also used it to calculate the total of the items.. the image below