Merge 2 maps at specific index - sass

I was wondering if I can merge 2 sass maps at a specific index of the first map.
$numbers: (
"one": 1,
"two": 2,
"three": 3,
"six": 6,
"seven": 7,
);
$more-numbers: (
"four": 4,
"five": 5,
);
#debug map.merge($numbers, $more-numbers);
// ("one": 1, "two": 2, "three": 3, "six": 6, "seven": 7, "four": 4, "five": 5)
Instead, I want:
("one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7)
I tried with the list module functions list.index() list.set-nth() but it replaces the index
$index: list.index($numbers, (three 3));
#debug list.set-nth($numbers, $index, $more-numbers);
// "one" 1, "two" 2, ("four": 4, "five": 5), "six" 6, "seven" 7
Even if that worked I am not sure how I can convert it back to a map.
Edit because someone asked the reason behind my question..
I am experimenting with generating utility classes.
u-padding-1: { padding: 0.375rem; }
I have already a map with the values:
$padding: (
"properties": (
"-padding": padding,
),
"directions": (
null: null,
"-horizontal": "-left" "-right",
"-vertical": "-top" "-bottom",
"-top": "-top",
"-right": "-right",
"-bottom": "-bottom",
"-left": "-left",
),
"values": (
"-none": 0rem,
"-tiny": t.rem(t.spacing(tiny)),
"-small": t.rem(t.spacing(small)),
null: t.rem(t.spacing(base)),
"-large": t.rem(t.spacing(large)),
"-huge": t.rem(t.spacing(huge)),
"-auto": auto,
),
) !default;
Now instead of manually adding all the utility key value pairs in the $padding->"values"
"-0": 0,
"-1": 1,
...
I generate them with a while loop and merge them. That would not be an issue but I need these utility classes to be added just before the keyword values like auto, full, etc. for cascading reasons.
I don't want to add another key value pair to my map, for example
"keywords: (
"-auto": auto,
"-full": 100%,
....
),
because I also generate responsive classes and it gets messy.
This is an example of a partial file.
#use "sass:map";
#use "sass:math";
#use "../settings/index.settings" as s;
#use "../tools/index.tools" as t;
$margin: (
"properties": (
"-margin": margin,
),
"directions": (
null: null,
"-horizontal": "-left" "-right",
"-vertical": "-top" "-bottom",
"-top": "-top",
"-right": "-right",
"-bottom": "-bottom",
"-left": "-left",
),
"values": (
"-none": 0px,
"-tiny": t.rem(t.spacing(tiny)),
"-small": t.rem(t.spacing(small)),
null: t.rem(t.spacing(base)),
"-large": t.rem(t.spacing(large)),
"-huge": t.rem(t.spacing(huge)),
"-auto": auto,
),
) !default;
// Populate map with values
$margin-arithmetic-progress: ();
$m: 0;
#while $m <= (t.strip-unit(s.$global-baseline) * 5) {
$converted: t.rem($m);
$margin-arithmetic-progress: map.set($margin-arithmetic-progress, "values", "-#{math.div($m, t.strip-unit(s.$global-baseline))}", $converted);
$m: $m + t.strip-unit(s.$global-baseline);
}
$margin: map.deep-merge($margin, $margin-arithmetic-progress);
#include t.generate-classes($margin);
#include t.generate-responsive-classes($margin);

Related

How to custom OrderBy in Laravel

I wanted to do a custom ordering for marketing_status_id in this:
$prospect = $this->filterProspect($request->all())
->select([
'student_marketings.*',
'students.name',
'students.identification_type_id',
])
->distinct('student_marketings.id')
->orderBy('student_marketings.marketing_status_id');
How to order it in this sequence: ('marketing_status_id', 5, 20, 4, 1, 3, 18, 6) ?
Use mysql inbuilt-method field() like this:
$prospect = $this->filterProspect($request->all())
->select([
'student_marketings.*',
'students.name',
'students.identification_type_id',
])
->distinct('student_marketings.id')
->orderBy(DB::raw('FIELD(marketing_status_id, 5, 20, 4, 1, 3, 18, 6)'));

how to display data in a table column using fpdf

My piece of code is:
for ( $i=2060; $i< $FINAL; $i++ ) {
$pdf->Cell( 36, 12, ( '05/' .number_format( $dataRow[$i] ) ), 1, 0, 'C', $fill );
}
expected pdf output as a column of cells using fpdf is:
05/2060
05/2061
05/2062
05/2063
05/2064
please guide me how to get the above desirable output.
Try adding 1 on the ln part instead of 0
for ( $i=2060; $i< $FINAL; $i++ ) {
$pdf->Cell( 36, 12, ( '05/' .number_format( $dataRow[$i] ) ), 1, 1, 'C', $fill );
}
and make sure that $FINAL has a value and you can do '05/'.$i also, and $fill must be true or false

Getting max and min from two different sets in json

I haven't found a solution with data set up quite like mine...
var marketshare = [
{"store": "store1", "share": "5.3%", "q1count": 2, "q2count": 4, "q3count": 0},
{"store": "store2","share": "1.9%", "q1count": 5, "q2count": 10, "q3count": 0},
{"store": "store3", "share": "2.5%", "q1count": 3, "q2count": 6, "q3count": 0}
];
Code so far, returning undefined...
var minDataPoint = d3.min( d3.values(marketshare.q1count) ); //Expecting 2 from store 1
var maxDataPoint = d3.max( d3.values(marketshare.q2count) ); //Expecting 10 from store 2
I'm a little overwhelmed by d3.keys, d3.values, d3.maps, converting to array, etc. Any explanations or nudges would be appreciated.
I think you're looking for something like this instead:
d3.min(marketshare, function(d){ return d.q1count; }) // => 2.
You can pass an accessor function as the second argument to d3.min/d3.max.

Creating a new column in JMP using an if condition from another column

I am very new in JMP so I am still feeling around.
I want to create a new column called "Status" in JMP. This status is character and depends on the value of the column "Grade". If the value of the entry in column "Grade" is zero, the value of the entry in column "Status" should be "fail". If the "Grade" value is greater than 100, the entry in column "Status" should be "invalid". If the :Grade" value is less than 0, the "Status" value should be "invalid". This should be simple. But somehow, my script won't work:
dt = Current Data Table();
dt << New Column("Status", Character, Formula(
If(:Name( "Grade" )==0, "fail",
:Name( "Grade" )>100, "invalid",
:Name( "Grade" )<0, "invalid")
));
Can you help me debug this script?
I just tried the script and the formula is working for me.
Here is some JSL which is a bit more complete which also adds the "Grade" column upon which "Status" depends.
dt = Current Data Table();
dt << New Column( "Grade",
Numeric,
"Continuous",
Format( "Best", 12 ),
);
dt << New Column( "Status",
Character,
"Nominal",
Formula(
If(
:Grade == 0, "fail",
:Grade > 100, "invalid",
:Grade < 0, "invalid"
)
)
);
Perhaps the issue is that you don't already have a data table opened with a Grade column? Here's a script to create a brand new table with the formula and some values.
New Table( "Grading Test",
Add Rows( 7 ),
New Column( "Grade",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [45, 20, 100, 101, -4, 0, 120] )
),
New Column( "Status",
Character,
"Nominal",
Formula(
If(
:Grade == 0, "fail",
:Grade > 100, "invalid",
:Grade < 0, "invalid"
)
)
)
);
I created that by interactively creating the table and using the red-triangle menu and selected "Copy Table Script".
I tried JMP 12.0, which version are you using?

How to pluck by key name matching?

Say I have the following table:
[
{numberOfRedStripes: 7, numberOfBlueStripes: 6, stars: 50, foo: "bar"},
{numberOfRedStripes: 1, numberOfBlueStripes: 1, stars: 0, something: "else"}
]
How can I use regex in order to pluck only the docs which their KEYS start with the string 'numberOf', so that the result would be:
[
{numberOfRedStripes: 7, numberOfBlueStripes: 6},
{numberOfRedStripes: 1, numberOfBlueStripes: 1}
]
?
Does this work?
table.map {|row|
row.pluck(r.args(row.keys().filter{|key| key.match("^numberOf")}))
}

Resources