var imagesHTML = {
a: "<img src='img/1.png' alt='a'>",
b: "<img src='img/2.png' alt='b'>",
c: "<img src='img/3.png' alt='c'>"
};
var forDraw = ['a', 'a', 'a', 'b', 'b', 'c'];
var data = forDraw.reduce(function (result, imageKey) {
if (!result[imageKey]) {
result[imageKey] = {html: imagesHTML[imageKey], count: 1};
} else {
result[imageKey].count++;
}
return result;
}, {});
var html = '';
Object.keys(data).forEach(function (key) {
html += data[key].html;
if (data[key].count > 1) {
html += 'X' + data[key].count;
}
html += '\n';
});
alert(html);