var m = [ ['Euroshop', 2500, 7500] , ['Euroshop', 2500, 7500], ['Tur', 2500, 7500] ];
var TOTAL_PAINTING = 3;
var m2 = [];
for (var i = 0; i < TOTAL_PAINTING; i++) {
if (m2.length == 0){
m2.push(m[i][0]);
m2.push(m[i][1]);
m2.push(m[i][2]);
}
else {
debugger;
var status = true;
var price = 0;
for (var j = 0; j < m2.length; j++) {
if (m2[j] == m[i][0]) {
for (var g = m2.length; g >= 0; g--) {
if (m2[j] == m[i][0]){
m2[j+1] = m2[j+1] + m[i][1]
}
}
status = false;
}
}
if (status == true){
m2.push(m[i][0]);
m2.push(price);
m2.push(m[i][2]);
}
}
}
var m = [['Euroshop', 2500, 7500],
['Euroshop', 2500, 7500],
['Tur', 2500, 7500]];
var temp = m.reduce(function(prev, el) {
if (prev.hasOwnProperty([el[0]]))
prev[el[0]] = [prev[el[0]][0]+el[1], prev[el[0]][1]+el[2]];
else
prev[el[0]] = [el[1], el[2]];
return prev;
}, {});
console.log(temp);
var result = [];
for (var name in temp)
result.push(name, temp[name][0], temp[name][1]);
console.log(result);
var m1 = [['Euroshop', 2500, 7500], ['Euroshop', 2500, 7500], ['Tur', 2500, 7500]],
m2 = [],
helper = {};
for (var i = 0; i < m1.length; i++) {
var name = m1[i][0],
data = m1[i].slice(1);
if (name in helper) {
helper[name][0] += data[0];
helper[name][1] += data[1];
} else {
helper[name] = data;
}
}
for (var key in helper) {
m2.push(key, helper[key][0], helper[key][1]);
}
console.log(m2);
for (var i = 0; i < TOTAL_PAINTING; i++) {
if (m2.length == 0){
m2.push(m[i][0]);
m2.push(m[i][1]);
m2.push(m[i][2]);
}
else {
var status = true;
var price = 0;
for (var j = 0; j < m2.length; j++) {
if (m2[j] == m[i][0]) {
for (var g = m2.length; g >= 0; g--) {
if (m2[g] == m[i][0]){
m2[j+1] = m2[j+1] + m[i][1]
m2[j+2] = m2[j+2] + m[i][2]
}
}
status = false;
}
}
if (status == true){
m2.push(m[i][0]);
m2.push(m[i][1]);
m2.push(m[i][2]);
}
}
}