d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Javascript Task: Extract Strings From Text File. > 500fg Each
Add Reply New Topic New Poll
Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
May 6 2019 04:51pm
https://pastebin.com/350qHczY

The output should be all the hexcodes with a umbrella color for each.
Write your js code in codepen or jsfiddle.

Example:

Red
1. #FFEBEE
2. #FFCDD2
3. #EF9A9A
...

Yellow

1. ...

And so on.
And so on.



This post was edited by kdog3682 on May 6 2019 04:53pm
Member
Posts: 4,103
Joined: Dec 4 2018
Gold: 870.16
May 7 2019 09:50am
Quote (kdog3682 @ May 6 2019 11:51pm)
https://pastebin.com/350qHczY

The output should be all the hexcodes with a umbrella color for each.
Write your js code in codepen or jsfiddle.

Example:

Red
1. #FFEBEE
2. #FFCDD2
3. #EF9A9A
...

Yellow

1. ...

And so on.
And so on.


color groups are subjective. can you post exactly which groups you want? red can include salmonish colors, but so can pink or orange..
there are multiple ways to define rules for sorting in groups.
one example is 3 groups, based on highest value (#xxyyzz where xx > yy && xx > zz means it's red)

if you look at https://www.w3schools.com/colors/colors_groups.asp you can see how there is overlap between groups.

This post was edited by Touta on May 7 2019 09:56am
Member
Posts: 6,991
Joined: Apr 16 2019
Gold: 50.00
May 7 2019 11:25am
Quote (Touta @ May 7 2019 11:50am)
color groups are subjective. can you post exactly which groups you want? red can include salmonish colors, but so can pink or orange..
there are multiple ways to define rules for sorting in groups.
one example is 3 groups, based on highest value (#xxyyzz where xx > yy && xx > zz means it's red)

if you look at https://www.w3schools.com/colors/colors_groups.asp you can see how there is overlap between groups.


But in the raw data its a pretty easy thing to do via RegExp

I just don't know JS to do it in that language.

But, the first step would be to grab everything inbetween these tags

Code
<li>(.*?)</li>


Which would give you this for the first result

Code

<li><h2>Red</h2><span class="design-asset-copy-as" data-clipboard-text="#FFEBEE" style="background-color: #FFEBEE;"></span><span class="design-asset-copy-as" data-clipboard-text="#FFCDD2" style="background-color: #FFCDD2;"></span><span class="design-asset-copy-as" data-clipboard-text="#EF9A9A" style="background-color: #EF9A9A;"></span><span class="design-asset-copy-as" data-clipboard-text="#E57373" style="background-color: #E57373;"></span><span class="design-asset-copy-as" data-clipboard-text="#EF5350" style="background-color: #EF5350;"></span><span class="design-asset-copy-as" data-clipboard-text="#F44336" style="background-color: #F44336;"></span><span class="design-asset-copy-as" data-clipboard-text="#E53935" style="background-color: #E53935;"></span><span class="design-asset-copy-as" data-clipboard-text="#D32F2F" style="background-color: #D32F2F;"></span><span class="design-asset-copy-as" data-clipboard-text="#C62828" style="background-color: #C62828;"></span><span class="design-asset-copy-as" data-clipboard-text="#B71C1C" style="background-color: #B71C1C;"></span><span class="design-asset-copy-as" data-clipboard-text="#FF8A80" style="background-color: #FF8A80;"></span><span class="design-asset-copy-as" data-clipboard-text="#FF5252" style="background-color: #FF5252;"></span><span class="design-asset-copy-as" data-clipboard-text="#FF1744" style="background-color: #FF1744;"></span><span class="design-asset-copy-as" data-clipboard-text="#D50000" style="background-color: #D50000;"></span></li>


Which you could then perform another RegExp to get the color umbrella name.

Code
<h2>(.*?)</h2>


Which would give you

Code
Red


And then a third RegExp to get all the color codes for that color

Code
background-color: #(.*?);


Which would give you

[code]FFEBEE
FFCDD2
ect..[/code]

And then just stick all that into a For loop and you're good to go :D


This post was edited by 3oDAtlas on May 7 2019 11:25am
Member
Posts: 4,103
Joined: Dec 4 2018
Gold: 870.16
May 7 2019 11:33am
Quote (3oDAtlas @ May 7 2019 06:25pm)
...


if groups are included in data, then your solution is good assuming the colorcodes follow the same regular expression.

easy fg if you add the data to a string literal variable, and iterate over regexp matches in the string literal variable / script with text body.

This post was edited by Touta on May 7 2019 11:35am
Member
Posts: 6,991
Joined: Apr 16 2019
Gold: 50.00
May 7 2019 11:35am
Quote (Touta @ May 7 2019 01:33pm)
if groups are included in data, then your solution is good assuming the colorcodes follow the same regular expression.

easy fg if you add the data to a string literal variable, and iterate over regexp matches in the string literal variable / script with text body.


Yeah its a pretty easy code, I just don't know / have 0 desire to learn a new language :D
Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
May 7 2019 03:58pm
Quote (Touta @ May 7 2019 11:50am)
color groups are subjective. can you post exactly which groups you want? red can include salmonish colors, but so can pink or orange..
there are multiple ways to define rules for sorting in groups.
one example is 3 groups, based on highest value (#xxyyzz where xx > yy && xx > zz means it's red)

if you look at https://www.w3schools.com/colors/colors_groups.asp you can see how there is overlap between groups.


The color groups are defined in the pastebin.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll