const str = 'helloosszsz'
let arr = str.split('')
const filteredArr = []
function run() {
let ind = false
const firstChar = arr[0]
for (let i = 1; i < arr.length; i++) {
const char = arr[i]
if (char === firstChar) {
if (ind) break
ind = true
}
if (i === arr.length - 1 && ind === true) {
filteredArr.push(firstChar)
}
}
arr = arr.filter(char => firstChar !== char)
if (arr.length) run()
}
run()
console.log(filteredArr)