This would be more efficient (and prettier) if written as:
```js
if (hex.length == 3) {
    hex = hex.replace(/(\w)/g, '$1$1');
}
```