Closest perf
by Julien Etienne
JavaScript
const array = Array(1000).fill();
const arrayLength = array.length;
let element = document.createElement('div');
let haystack;
let needle;
array.forEach((_, i) => {
if (i === 0) {
haystack = element;
haystack.className = 'haystack';
}
const newElement = document.createElement('div');
if(i === arrayLength - 1){
newElement.className = 'needle';
needle = newElement;
}
element.appendChild(newElement);
element = newElement;
});
console.time('closestTime')
console.log(needle.closest('.haystack'));
console.timeEnd('closestTime')