Logo

Programming-Idioms

History of Idiom 119 > diff from v48 to v49

Edit summary for version 49 by programming-idioms:
[JS] Original order is preserved.

Version 48

2019-01-03, 09:53:54

Version 49

2019-01-03, 09:54:00

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Illustration

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Illustration
Extra Keywords
deduplicate dupe dupes redundant redundancy undupe
Extra Keywords
deduplicate dupe dupes redundant redundancy undupe
Code
const seen = new Set();
x = x.filter( v => {
  if(seen.has(v))
    return false;
  seen.add(v);
  return true;
});
Code
const seen = new Set();
x = x.filter( v => {
  if(seen.has(v))
    return false;
  seen.add(v);
  return true;
});
Comments bubble
Original order is preserved.
Doc URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
Doc URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
Origin
https://twitter.com/addyosmani/status/1080727964411674624?s=09
Origin
https://twitter.com/addyosmani/status/1080727964411674624?s=09