The facts:
- I have several arrays (anywhere from 2 to dozens), all comprised of CSS classes.
- Every class in each array is namespaced with one of the following:
'alignment__','font__','leading__','size__', or'tracking__'. - The values in the arrays will not usually be in the same order.
- The arrays will not always contain a value for each namespaced class.
What I need:
- If the value for each namespace is the same in every array, I need to return the
classNamewithout the namespace. - If the value for any namespace is different in any array, I need to return
false.
Example:
Here is a small example of a collection of arrays I’ll be working with:
p1 = ["alignment__left", "size__18px", "leading__170", "tracking__0", "font__Operator--1408"];
p2 = ["size__18px", "tracking__0", "font__Operator--1408", "alignment__left"];
p3 = ["alignment__left", "size__18px", "leading__170", "tracking__0", "font__Operator--1408"];
p4 = ["alignment__left", "size__18px"];
This collection of arrays should return something like:
return {
alignment: 'left',
font: false,
leading: false,
size: '18px',
tracking: false
}
Suggestions? Every angle I approach this from just seems slow and inefficient. I’m using lodash in this project, in case that simplifies things at all.