Created
April 20, 2018 01:11
-
-
Save kubarium/88beff342bff0941618062d1f26dc983 to your computer and use it in GitHub Desktop.
Using Reduce to Remove Duplicates: http://denizkumsal.com/programming/using-reduce-to-remove-duplicates/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.removeDuplicates = function(){ | |
return this.reduce((result,nextItem)=>result.includes(nextItem) ? result : result.concat(nextItem),[]); | |
} |
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
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