example
var string = "ACABBCAA";
var a = "A";
var b = "B";
var c= "C";
output:
removeLastChar(string,a); //output ACABBCA
removeLastChar(string,b); //output ACABCAA
removeLastChar(string,c); //output ACABBAA
What I have tried so far?
Solution 1
function removeLastChar(string,char){
result = string.replace(new RegExp('/'+char+'$/'), "");
return result;
}
Solution 2
function removeLastChar(string,char){
result = string.replace('/'+char+'$/', "");
return result;
}
I already asked in the comments here but not working out.