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