Skip to content

Instantly share code, notes, and snippets.

@longfellowone
Last active April 29, 2019 05:05
Show Gist options
  • Save longfellowone/4bfa9f703e8edc55425739ea0484fd42 to your computer and use it in GitHub Desktop.
Save longfellowone/4bfa9f703e8edc55425739ea0484fd42 to your computer and use it in GitHub Desktop.
replaceAtReducer
function replaceAt(indexArray, string) {
const func = (string, i) => {
string[i] = (
<span className="font-bold text-red" key={i}>
{string[i]}
</span>
);
return string;
};
return indexArray.reduce(func, [...string]);
}
const replaceAt = (indexArray, string) =>
indexArray.reduce(
(string, i) => {
string[i] = <b>{string[i]}</b>;
return string;
},
[...string]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment