function homework() {
var pupils = ["John Michael Kane", "Kayne A B", "Andrew Garcia K", "Shon M D", "John D K"],
countOccurrence = {},
element = document.createElement("DIV");
for(var i = 0, leng = pupils.length, pupil = ""; i < leng; i++) {
element = document.createElement("DIV");
element.innerHTML = pupils[i];
pupil = pupils[i].replace(/\s(\w){1,}/g, "");
if(countOccurrence[pupil]) {
countOccurrence[pupil]++;
}
else {
countOccurrence[pupil] = 1;
}
document.body.appendChild(element);
}
for(var name in countOccurrence) {
element = document.createElement("DIV");
element.innerHTML = name + " is used " + countOccurrence[name];
document.body.appendChild(element);
}
}
window.onload = homework;