Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Created April 29, 2020 08:23
Show Gist options
  • Save sandrabosk/7392010a8314527745921f9eedbf3a11 to your computer and use it in GitHub Desktop.
Save sandrabosk/7392010a8314527745921f9eedbf3a11 to your computer and use it in GitHub Desktop.
// ************************************************************************************
// https://www.codewars.com/kata/54f9f4d7c41722304e000bbb/javascript
// Find the first character that repeats in a String and return that character.
// firstDup('tweet') => 't'
// firstDup('like') => undefined
// This is not the same as finding the character that repeats first. In that case,
// an input of 'tweet' would yield 'e'.
// ************************************************************************************
function firstDup(str) {
return str
.split('')
.filter((elem, i, arr) => arr.indexOf(elem) !== arr.lastIndexOf(elem))[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment