I want to visualize top/window frames recursion in the following manner, using simple/vanilla JavaScript (using traversing window/top tree array structure, like shown in Developer Tab, as below)
What JS code using loop/recursion to be written to get following type output for each nested frames structure (once such frames structure could be seen at W3Schools Online Web Tutorials page- https://www.w3schools.com, 42 frames/IFrames are present in this page, and it is needed to get a list by JavaScript code)
top : Name/URL Topmost-Window
top[0] : Title/Name/URL of the Frame/IFrame
top[1] : Title/Name/URL of the Frame/IFrame
top[1][0] : Title/Name/URL of the Frame/IFrame
top[1][1] : Title/Name/URL of the Frame/IFrame
top[1][1][0] : Title/Name/URL of the Frame/IFrame
top[1][1][1] : Title/Name/URL of the Frame/IFrame
top[1][2] : Title/Name/URL of the Frame/IFrame
top[3] : Title/Name/URL of the Frame/IFrame
top[4] : Title/Name/URL of the Frame/IFrame
top[4][0] : Title/Name/URL of the Frame/IFrame
top[4][1] : Title/Name/URL of the Frame/IFrame
top[4][2] : Title/Name/URL of the Frame/IFrame
top[4][2][0] : Title/Name/URL of the Frame/IFrame
top[4][2][1] : Title/Name/URL of the Frame/IFrame
top[4][2][1][0] : Title/Name/URL of the Frame/IFrame
top[5] : Title/Name/URL of the Frame/IFrame
top[6] : Title/Name/URL of the Frame/IFrame
top[7] : Title/Name/URL of the Frame/IFrame
top[8] : Title/Name/URL of the Frame/IFrame
top[8][0] : Title/Name/URL of the Frame/IFrame
top[8][1] : Title/Name/URL of the Frame/IFrame
top[8][2] : Title/Name/URL of the Frame/IFrame
top[8][3] : Title/Name/URL of the Frame/IFrame
top[9] : Title/Name/URL of the Frame/IFrame
top[10] : Title/Name/URL of the Frame/IFrame
top[11] : Title/Name/URL of the Frame/IFrame
etc.
Related
I have a Google Sheet that contains data I need to manipulate. It is essentially a list of assignments by student. The original columns are:
Name, ID, Assignment 1, Assignment 2, Assignment 3, Assignment 4, Date, Overall Grade
Using existing code, I am concatenating the Assignments into a single field and creating an array with these columns:
ID, Name, Assignments, Date, Overall Grade
The resulting array looks like this:
[ [ '1234',
'Santa Claus',
'US History Chapter 1.1, , , ',
Fri Nov 18 2022 00:00:00 GMT-0800 (Pacific Standard Time),
'B+' ],
[ '1234',
'Santa Claus',
'US History Chapter 2.1, US History Chapter 1.1, , ',
Thu Nov 17 2022 00:00:00 GMT-0800 (Pacific Standard Time),
'B' ],
[ '12222',
'Mary Poppins',
'US History Chapter 8, , , ',
Fri Nov 18 2022 00:00:00 GMT-0800 (Pacific Standard Time),
'A' ]]
On a separate sheet I have a list of dates. What I want is to have a line for every single student and date combination and the assignment data if it exists. E.g. If the dates are Nov 17, Nov 18, and Nov19 and there are 2 students with data in the list, there would be 6 total entries sorted by student then by date. For the Assignments column, there would only be data if there was an assignment entered for that date and that student. Otherwise it would be blank. For example:
ID
Name
Assignments
Date
Grade
1234
Santa Claus
Chapter 2.1, US History Chapter 1.1
Nov17
B
1234
Santa Claus
US History Chapter 1.1
Nov18
B+
1234
Santa Claus
Nov19
12222
Mary Poppins
Nov17
12222
Mary Poppins
US History Chapter 8
Nov 18
A
12222
Mary Poppins
Nov19
What I think is needed is something like this:
Get unique list of all student IDs from the array
Get list of dates from the sheet
Use a nested loop to go through each date and each student to create the lines. If there is a match for the assignment data, add it, if not, leave that blank.
I'm just not sure how to manipulate the array to do something like that. How would I approach this?
Although, unfortunately, I cannot know your actual array, from your showing sample array and a sample table, how about the following sample script?
Sample script:
const array = [,,,]; // Please set your array.
const res = Object.entries(array.reduce((o, e) => (o[e[0]] = o[e[0]] ? [...o[e[0]], e] : [e], o), {}))
.sort(([a], [b]) => Number(a) > Number(b) ? 1 : -1)
.flatMap(([, v]) => v.sort((a, b) => a[3].getTime() > b[3].getTime() ? 1 : -1));
console.log(res)
In this sample script, first, an object is created by checking the column "A". And, sort the array by the column "A". And, for each element, sort the column "D". And, all values are merged as a 2-dimensional array.
Note:
If this sample script doesn't return your exected values, can you provide the detailed sample input values and the sample output values? By this, I would like to confirm it.
References:
reduce()
sort()
I have a fitness application that I am working on. I have integrated fitbit/garmin with it.
So the heart-rates data that I get from these vendors, are on a unix timestamp basis:
HEARTRATES COLLECTION
1614975688461 : 58BPM
1614975688461 : 33BPM
1614975688461 : 99BPM
1614975688461 : 44BPM
1614975688461 : 67BPM
1614975688461 : 89BPM
I have a collection in my mongoDB, which maps each of these timestamps to the heartrate.
Now I plan on having a chart which shows the weekly, monthly and the yearly average of the heart-rate for that person.
Now to do this, I can always do a less than greater query on the timestamp in my db(span of 30 days for months and span of 365 days for the yearly plot), compute and get the average on the application and show. But my doubt is, will this scale for like a million users?
Alternation solution that I have in mind: Each time the person syncs their fitbit/garmin device, I run cronjobs at the end of each day which updates collections "Weekly" and "Yearly" for each user. This way all the app has to do is query the weekly collection for the weekly data starting from the query date or the yearly collection for the data starting from the query date.
WEEKLY COLLECTION : WHICH UPDATES EVERDAY:
DAY 1: 56BPM
DAY 2: 56BPM
DAY 3: 56BPM
DAY 4: 56BPM
DAY 5: 56BPM
DAY 6: 56BPM
DAY 7: 56BPM
Does the alternate solution make any sense or is it making things worse? If you have any better solution, please let me know, thanks!
I have a date format of
12March2018
I am trying to get a regular expression to identify the pattern using a regex expression. 1st letter must be numeric.Followed by the first 3 letters of the month. If the word which follows the numeric matches with any first 3 letter of any month it should return true. How do I get it?
Can you try using this regex:
/(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)/g
In your case for identifying March from 12March2018, you can use as:
(?:Mar(?:ch))
Here (?:Mar) is for identifying a month which is denote by 3 character (simple representation). And by using (?:ch), the full name of the month is matched or identified from string.
You can test this here.
if you wanna match groups of months, say, those with 31-days, with all input being first 3 letters, properly cased, here's the most succinct regex I could conjure up to match all 7 of months using just 4 letters :
{m,g,n}awk '/[acgl]/'
Jan J [a] n
Mar M [a] r
May M [a] y
Jul J u [l]
Aug A u [g]
Oct O [c] t
Dec D [c] t
if they're already all lowercased, then
/[^a]a|[cgl]/
/a[^p]|[cgl]/
jan
mar
may
jul
aug
oct
dec
for the 30-day ones, regardless of proper or lowercase,
/p|v|un/
apr a [p] r
jun j [u][n]
sep s e [p]
nov n o [v]
if you wanna match what people frequently describe as then "summer months", despite that not being officially defined :
/u/
Jun J [u] n
Jul J [u] l
Aug A [u] g
just the 4th-quarter months :
/[cv]/
Oct
Nov
Dec
depending on whether you want to maximize the amount of months captured, or require uniqueness, here's a quick reference table as to uniqueness of the first 3 letters, when properly cased :
repeated : unique DFNOS bglotvy
repeated : 2-times AM cnpr
repeated : 3-times J aeu
when they're all uni-cased :
repeated : unique BDFGLSTVY repeated : 3-times EJNU
repeated : 2-times CMOPR repeated : 5-times A
when you include every letter of their full english names, uni-cased:
repeated : unique FGHIV repeated : 6-times U
repeated : 2-times DLPS repeated : 8-times A
repeated : 3-times CJOT repeated : 9-times R
repeated : 4-times NY repeated : 11-times E
repeated : 5-times BM
I have a dataset that looks something like this:
MONTH CAT VAL
may A 1.0
may B 3.2
may C 4.6
jun A 2.7
jun B 4.2
jun C 5.8
jul A 4.1
jul B 9.2
jul C 13.0
I've been able to create a chart in DC.js that shows the sum of VAL according to the CAT variable, with this code:
let chart = dc.barChart('#chart');
let ndx = crossfilter(data);
let catDim = ndx.dimension(function(d){return d.cat;});
let catGroup = catDim.group().reduceSum(function(d){return +d.val;});
chart
.dimension(catDim)
.group(catGroup)
.x(d3.scale.ordinal().domain(catDim))
.xUnits(dc.units.ordinal)
.elasticY(true)
My problem is that instead of the sum, I would like to show in the grafic the average of VAL per MONTH for each CAT (MONTH can be filtered in another graph).
Is there a way to do it?
Thanks in advance for your answers!
So instead of using crossfilter to "just" keep track of the sum, use a custom reduce that tracks both the sum and the number of items, and add a valueAccessor to return x.value.sum/x.value.qty
I would suggest you to use reductio to handle the custom reduce, check the examples, you have one for the average.
I have to implement a subscription where users can choose to subscribe his products which will get delivered to him on each alternate from the date he subscribed or with a Two Day Gap from the subscribed date.
//Sample Data
[
{
"subscribed_on": ISODate("2017-01-01T08:15:39.736Z"),
"_id" : 1,
"customer" : "jon doe",
"type": "alternate"
},
{
"subscribed_on": ISODate("2017-01-02T08:15:39.736Z"),
"_id" : 1,
"customer" : "Doe John",
"type": "Two Day Gap"
},
{
subscribed_on: ISODate("2017-01-02T08:15:39.736Z"),
"_id" : 1,
"customer" : "Foo Name",
"type": "alternate"
}
]
Now for each day I have to query to find the list of the customers which have the delivery for today's date.
How can I aggregate so that I can calculate if the current date is the alternate date or lies in two-day gap?
To simplify the query for alternate I can check if the current date is even or odd and will query the date opposite it. Like if the current date is 1st Jan which is odd I can query to find the date which is even for alternate subscription query. Is this correct efficient way for finding alternate date?
What will be the current way to find the subscription for Two Day Gap type?