javascript – implementation of methods and calculations in Vuex

import View of "view";
import Vuex from "vuex";

var actions = _buildActions ();
var modules = {};
mutations var = _buildMutations ();

constant state = {
moyenneRégion: [],
};

Vue.use (Vuex);



getters const = {
avgArray (region) {
const sum = arr => arr.reduce ((a, c) => (a + = c), 0);
const avg = arr => sum (arr) / arr.length;

average return (region);
}
groupedPrices () {
return state.averageRegion.reduce ((acc, obj) => {
var key = obj.region;
if (! acc[key]) {
access[key] = [];
}
access[key].push (obj.m2_price);
return acc;
}, {});
}
averageRegion () {
let arr = [];
Object.entries ()
.for each(([key, value]) => {
arr.push ({ [key]: Math.round (avgArray (value))});
});

back arr;
}
};

function _buildActions () {
return {
fetchData ({commit}) {
axios
.get ("/ ajax")
.then (answer => {
commit ("SET_DATA", response.data);
// console.log ("data", response.data);
})
.catch (error => {
commit ("SET_ERROR", error);
});
}
};
}

function _buildMutations () {
return {
SET_DATA (status, payload) {
// console.log ("payload", payload);
state.storedData = payload;
}
};
}

export by default the new Vuex.Store ({
actions: actions,
modules: modules,
mutations: mutations,
state: state,
getters
});