So, i wrote this Javascript Function Which Return a Hex code as a String. Is there a way through which i can reduce the size of this code
function RandomHexGenerator(Opacity) {
const Chars = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f'];
let HexContainer = [];
while (HexContainer.length != 6) {
HexContainer.push(Chars[Math.floor(Math.random() * Chars.length)]);
}
let HexString = HexContainer.toString();
let CleanString = HexString.replaceAll(',', '');
if (Opacity != true) {
return '#' + CleanString;
} else {
let lastDigits = [];
while (lastDigits.length != 2) {
lastDigits.push(Chars[Math.floor(Math.random() * Chars.length)]);
}
let StringLastDigit = lastDigits.toString();
let CleanLastDigit = StringLastDigit.replaceAll(',', '');
return '#' + CleanString + CleanLastDigit;
}
}
I Just want to Know/Learn If there is way through which i can reduce the size of this code