In js there's reduce. Something like
arr.reduce((result, currentValue, currentIndex, original) => {
if(currentIndex < original.length - 2
&& original[currentIndendex + 2] % 2 === 0 ) {
result.push(currentValue / 2)
} else {
result.push(currentValue);
}
return result;
}, [])
This would map arr and return halved values for elements for which the element two steps ahead is even. This should be available in languages where map is present. And sorry for possible typos, writing this on mobile.