Good explanation and good job and making sure to add zeroes!
One small thing, though, pad functions add stuff to a string until the string reaches the desired length. So the ternary there is unnecessary.
let hex = digit().toString(16) //check if length is 2, if not pad with 0 hex = hex.length < 2 ? hex.padStart(2, 0) : hex;
The above code could be rewritten as:
let hex = digit().toString(16) hex = hex.padStart(2, 0)
Or even:
const hex = digit() .toString(16) .padStart(2, '0')
Thank you very much. Never even thought of that.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Good explanation and good job and making sure to add zeroes!
One small thing, though, pad functions add stuff to a string until the string reaches the desired length. So the ternary there is unnecessary.
The above code could be rewritten as:
Or even:
Thank you very much. Never even thought of that.