Let's say that someone asks a question, and I add this simple answer in code (context: create array of tags in document):
function countTag() {
let tags = [];
for (tag of document.getElementsByTagName("*")) {
tags.push(tag.tagName);
}
return tags;
}
console.log("Tags: ", countTag());
<div>a</div>
<div>b</div>
<div>c</div>
<div>d</div>
<div>e</div>
But later, I do more research and find a more compact, refined way to achieve the same result, but with different compatibility:
function countTag(tag="*") {
return [...document.getElementsByTagName(tag)].map(a => a.tagName)
}
console.log(countTag("*"))
<div>a</div>
<div>b</div>
<div>c</div>
<div>d</div>
<div>e</div>
If I want to add this new, refined code to my answer, what should I do? Should I create a new answer with the new code, add the new code as an "extra" to my original answer in an edit, or edit out the old answer entirely and replace it with the new answer?