Well, if you are going with Array.prototype.reduce, you better be not using any side-effects.
constroot=document.getElementById("root");if(!root){thrownewError("Root not found");}constfruits=["banana","apple","pear"];constinnerHTML=fruits.reduce((html,fruit,index)=>{return`${html}#${index+1}: ${fruit}<br>`;},"");root.innerHTML=innerHTML;
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
const fruits = ["banana", "apple", "pear"];
fruits.reduce((initalArr, value, currentIndex) => {
initalArr.push(
${currentIndex} --- ${value}
);return initalArr;
}, []);
Well, if you are going with
Array.prototype.reduce
, you better be not using any side-effects.