Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const result = arr.reduce((acc, val) => {
- if (acc.includes(val)) {
- const otherDuplicateIdx = acc.indexOf(val);
- acc[otherDuplicateIdx] = 3;
- return [...acc, 3];
- } else {
- return [...acc, val];
- }
- }, []);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement