NazariyM
3/19/2020 - 1:24 PM

get only dublicates from str

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)