JSFiddle - React, Tailwind, and code Playground

JavaScript

function unique(list) {
  var result = [];

  function findOccurrenceIndex(arr, val, index) {
    var i, j,
      count = 0;
    for (i = 0, j = arr.length; i < j; i++) {
      (arr[i] === val) && count++;
      if (i == index) {
        return count;
      }
    }
    return count;
  }

  $.each(list, function(i, e) {
    if (findOccurrenceIndex(list, e, i) < 3) result.push(e);
  });

  return result.join("");
}
var srting = "DGHKHHNL";
var thelist = srting.split("")
console.log(unique(thelist));