JSFiddle - React, Tailwind, and code Playground
JavaScript
var str = 'Hello to all from Boston';
function returnFirstRepeatChar2(str) {
return str.split(' ').reduce(function (p, c) {
var hasDupes = c.toLowerCase().split('').sort().join('').match(/(.)\1+/g);
if (hasDupes) p.push(c);
return p;
}, []);
}
console.log(returnFirstRepeatChar2(str))