Skip to content

Instantly share code, notes, and snippets.

@kubarium
Created April 20, 2018 01:11
Show Gist options
  • Save kubarium/88beff342bff0941618062d1f26dc983 to your computer and use it in GitHub Desktop.
Save kubarium/88beff342bff0941618062d1f26dc983 to your computer and use it in GitHub Desktop.
Array.prototype.removeDuplicates = function(){
return this.reduce((result,nextItem)=>result.includes(nextItem) ? result : result.concat(nextItem),[]);
}
Copy link

ghost commented Aug 13, 2018

Very beautiful use of reduce function, but in the above example, the above function does not work for any of the internet explorers as "includes" function is not supported by internet explorer

@kubarium
Copy link
Author

kubarium commented Feb 8, 2019

Very beautiful use of reduce function, but in the above example, the above function does not work for any of the internet explorers as "includes" function is not supported by internet explorer

You could, alternatively, use indexOf instead of includes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment