Advertisement
Guest User

Untitled

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