I want to remove the third occurrence of a character from a string.
Below is what I tried from my end:
function unique(list) {
var result = [];
function findOccurrences(arr, val) {
var i, j,
count = 0;
for (i = 0, j = arr.length; i < j; i++) {
(arr[i] === val) && count++;
}
return count;
}
$.each(list, function(i, e) {
if (findOccurrences(list, e) < 3) result.push(e);
});
return result.join("");
}
var srting = "DGHKHHNL";
var thelist = srting.split("")
console.log(unique(thelist));
Here are some expected results:
Input: DGHKHHNL
Expected: DGHKHNL
Input: AFKLABAYBIB
Expected: AFKLABYBI
Input: JNNNKNND
Expected: JNNKD
https://regex101.com/r/WmUPWW/1 .. I tried using this regex as well to solve the issue. But this this doesn't solves the issue as well.
Please help