This is a small thing that I started working two days ago, thinking that it would be a small brain problem, and then I will return to eating my lunch again. However, it is difficult for them. I want to get an array of all valid hexadecimal color codes. No crashing is preferable.
This is what I came up with.
app.directive 'randomColor', () -> link: (scope) -> scope.colors = new Array col = 0x0 while col <= 0xFFF if (col > 0x111 && col < 0xFFF) scope.colors.push '#' + col col++ autocolor = (hexcode) -> colorChange = () -> $("#colorvomit").append("<span style='padding: 1px 10px 1px 10px;background-color: " +hexcode+";border: 1px solid black;'></span>") setTimeout(colorChange, 5000) _.each(scope.colors, autocolor)
Don't forget that I use coffescript and angular js. Using the underscore library so I can use _.each.
So, I get this as a result

you can see that there are a lot of white squares below, and this goes on forever, because it returns with invalid hex codes like # 1223 (4-digit).
So, here is my question: what is the best way to get all valid hexadecimal color codes allows me to say that 6 long I have 3 long (FFF), because it crashes otherwise without receiving invalid codes. Appreciate all your help, and I think it will be an interesting question.
I did my research and did not find anything like it. Because we want all of them to be in order, as well as 111 112 113 ect ...
source share