Typically, I create functions within the component that will use them. However, I am finding that I need to use a particular function in multiple components now. Currently, I would have to duplicate and paste the function into each component, which is not ideal. I am unsure of where I should place these functions for better organization. Here's an example of a general utility function:
winrate(wins, losses) {
let games = wins + losses
return Math.round(wins * 100 / games) + '%'
}
It's a simple function that calculates the win rate based on wins and losses.
I am utilizing Vuex and I could potentially store them there, but I'm unsure if that is the most efficient solution. Any advice would be greatly appreciated!