diga,
<div class="my_img"></div>
<script>
function fn(d) {
var b = 1,
e = 1,
a = "",
c = document.querySelector(".my_img");
d.forEach(function(f, c) {
f != d[++c] ? (a += "<img src='img/" + e + ".png' alt='" + f + "'>", e++, a += "<br>X" + b + "<br>", b = 1) : b++
});
c.insertAdjacentHTML("beforeBegin", a)
};
var arr = ['a','a','a','b','b','c'] ;
fn(arr)
</script>