Skip to content

Instantly share code, notes, and snippets.

@juanmaguitar
Created July 23, 2017 22:27
Show Gist options
  • Select an option

  • Save juanmaguitar/f23bca1c2240f0330b97f448ab90fa29 to your computer and use it in GitHub Desktop.

Select an option

Save juanmaguitar/f23bca1c2240f0330b97f448ab90fa29 to your computer and use it in GitHub Desktop.
Detect duplicates in an array
const isDuplicated = (element, i, array) => {
return array.filter( item => item === element).length > 1
}
const countries = ['Namibia','Niger','Palau','Macedonia','Brazil','Czech Republic','Mauritania','Canada','Sweden','Afghanistan','Singapore','Azerbaijan','Turkmenistan','Sao Tome and Principe','Denmark','Mongolia','Switzerland','St. Lucia','Nauru','Slovenia','Papua New Guinea','Cameroon','Iraq','Portugal','Zambia','Italy','Afghanistan','Burkina Faso','Dominica','Iceland','Serbia','Myanmar','Canada','Oman','United Kingdom','Tanzania','Jordan','Timor-Leste','Kosovo','Lithuania','Tuvalu','Palau','Latvia','Andorra','Belarus','Tajikistan','Indonesia','Hungary','Cambodia','Israel','Bangladesh','Peru','Moldova']
countries
.map( isDuplicated )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment