JSFiddle - React, Tailwind, and code Playground
by thewolff
JavaScript
const doesMyDickRepeat = (str) => {
let charArr = str.split('');
let sortedArr = str.split('').sort()
let matchingCar;
for(let i = 0, len = sortedArr.length; i <len; i++) {
if(sortedArr[i] === sortedArr[i+1]) {
matchingCar = sortedArr[i]
}
}
if(charArr.indexOf(matchingCar) > -1) {
return charArr.indexOf(matchingCar)
} else {
return -1
}
}
let s = 'dicknosey';
console.log(doesMyDickRepeat(s))