By neildaemond, an 'any-stack' hacking grasshopper.
Taking notes while tinkering with:

Create a hexadecimal colour based on a string with Elm

I had an html table of categorized items, and I wanted to give each category it’s own Color automatically. So I thought I’d hash the category ID String into an HTML Hexidecimal Color. A search will find this stack overflow post, but I was using elm and thought it would be a fun task to translate this function into a funcitonal style. Here’s how that went:

The Stack Overflow post provided the following solution in Javascript:

and I ended up with:

then, in each table row’s first td, I could add I colour indicator as follows:

td [style[("border-left","10pt solid " ++ (stringToHexColor item_variable.id))] ] [ text "The Item Name"]

I haven’t been able to confirm that it does exactly as the javascript function, but it seems to do the job i need it to for now. I now have an itch to delve more into Bitwise and write about that as well.


#Elm   #HashFunctions