function convertRGBAtoHEX(channels) {
const hexChannels = channels.map(entry => (`0${entry.toString(16)}`).slice(-2));
return (`#${hexChannels.join('')}`);
}
function parseRGBA(raw) {
const channels = raw
.replace(/rgba|rgb|\(|\)/g, '')
.split(/,\s*/g)
.map((entry, index) => {
const number = parseFloat(entry, 10);
return (index === 3) ? Math.floor(number * 255) : number;
});
return channels;
}
console.log(convertRGBAtoHEX(parseRGBA('rgba(255, 0, 100, .7)'))); // #ff0064b2
console.log(convertRGBAtoHEX([255, 0, 100, 178])); // #ff0064b2
console.log(convertRGBAtoHEX([255, 0, 100])); // #ff0064