Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<a href="http://denizkumsal.com/programming/using-reduce-to-remove-duplicates/">Using Reduce to Remove Duplicates</a>
</body>
</html>
 
/**
* http://denizkumsal.com/programming/using-reduce-to-remove-duplicates/ 
**/
Array.prototype.removeDuplicates = function(){
  return this.reduce((result,nextItem)=>result.includes(nextItem) ? result : result.concat(nextItem),[]);
}
numbers = [1,3,2,1,3,1,2];
names = ["John","Doe","Jane","Doe","Jeremy","Bentham","Jane"];
console.clear();
console.log(numbers.removeDuplicates());
console.log(names.removeDuplicates());
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
kubariumpro
0viewers