arrays

How to build a JSON object using collection of dot notation strings using JavaScript?

ⅰ亾dé卋堺 提交于 2021-02-11 18:19:43
问题 I have a collection of strings in an array. These strings are the JSON paths that i select from a checkbox tree. var selected = ['a', 'b.c.0.d', 'b.c.1.d', 'b.c.0.e', 'b.c.1.e']; I want to save it to the database with the real data given by the user. So i want to create a JSON object like following structure. It can be further nested. { "a":5, "b":{ "c":[ { "d":5, "e":5 }, { "d":5, "e":5 } ] } } 来源: https://stackoverflow.com/questions/59882169/how-to-build-a-json-object-using-collection-of

How to build a JSON object using collection of dot notation strings using JavaScript?

久未见 提交于 2021-02-11 18:18:18
问题 I have a collection of strings in an array. These strings are the JSON paths that i select from a checkbox tree. var selected = ['a', 'b.c.0.d', 'b.c.1.d', 'b.c.0.e', 'b.c.1.e']; I want to save it to the database with the real data given by the user. So i want to create a JSON object like following structure. It can be further nested. { "a":5, "b":{ "c":[ { "d":5, "e":5 }, { "d":5, "e":5 } ] } } 来源: https://stackoverflow.com/questions/59882169/how-to-build-a-json-object-using-collection-of

Spark Data set transformation to array [duplicate]

↘锁芯ラ 提交于 2021-02-11 18:16:14
问题 This question already has answers here : How to aggregate values into collection after groupBy? (3 answers) Closed 8 months ago . I have a dataset like below; with values of col1 repeating multiple times and unique values of col2. This original dataset can almost a billion rows, so I do not want to use collect or collect_list as it will not scale-out for my use case. Original Dataset: +---------------------| | col1 | col2 | +---------------------| | AA| 11 | | BB| 21 | | AA| 12 | | AA| 13 | |

How to filter an array of objects with names from another array of objects [duplicate]

喜你入骨 提交于 2021-02-11 17:53:40
问题 This question already has answers here : Filter array of objects with another array of objects (9 answers) Closed 5 months ago . I'm new to Javascript and I'm struggling with how to use the map, filter, find and other functions. I have two arrays of objects, and I wanted to filter the first one with the second. const users = [ { name: 'Anna', age: 22, gender: 'F' }, { name: 'John', age: 25, gender: 'M' }, { name: 'Mary', age: 27, gender: 'F' }, { name: 'Joe', age: 30, gender: 'M' } ] const

Compare a Datatable and string array in c#

大憨熊 提交于 2021-02-11 17:52:24
问题 I simply want to compare the first col of the datatable called "name" to items in the array. They can be multiple rows in the datatable with the same name. After it has compared all items in the array it should delete the rows that were NOT from the datatable. The output result can be the datatable itself or list array (prefer this) however this should retain all the columns from datatable. Possibly want to use linq query. code: DataTable dt = new DataTable("TestTable"); dt.Columns.Add(new

Compare 2 different Arrays by ID and calculate difference

穿精又带淫゛_ 提交于 2021-02-11 17:51:31
问题 I got 2 arrays ArrayA = {"data":{"PlayerList":[{"Platform":1,"PlayerExternalId":205288,"Price":250,"RemainingTime":22},{"Platform":1,"PlayerExternalId":205753,"Price":10000,"RemainingTime":22}]}} ArrayB = {"datafut": [{"currentPricePs4": "4149000","currentPriceXbox": "3328000","PlayerExternalId": "151152967"},{"currentPricePs4": "3315000","currentPriceXbox": "2720000","PlayerExternalId": "151198320"}]} ArrayB is like a small database to compare prices. ArrayA needs theoretically an

Passing byte array to PInvoke call changes it to null

夙愿已清 提交于 2021-02-11 17:46:15
问题 After migration from Visual Studio 2012 to 2013 some PInvoke calls not working as previously. For example, I'm struggling with this code: Signature: [DllImport(LzoDll64Bit)] private static extern int lzo1x_decompress(byte[] src, int src_len, byte[] dst, ref int dst_len, byte[] wrkmem); Usage: byte[] dst = new byte[origlen]; int outlen = origlen; if (Is64Bit()) lzo1x_decompress(src, src.Length - 4, dst, ref outlen, _workMemory); else lzo1x_decompress32(src, src.Length - 4, dst, ref outlen,

ES6 Sum by object property in an array

旧街凉风 提交于 2021-02-11 17:40:52
问题 I am trying to sum the unit value by date, and create a new array where there are no duplicate dates. For example, I want to calculate the total of 2015-12-04 00:01:00 . This date has occurred 2 times in the following data, its value is 5 and 6 , which is going to be: [{date: '2015-12-04 00:01:00', unit: 11}, ... etc] I have tried arr = results.map(x => x.unit).reduce((a,c) => a + c) but it only return a single value, not an array. results = [ { unit: 5, date: '2015-12-04 00:01:00' }, { unit:

ES6 Sum by object property in an array

蹲街弑〆低调 提交于 2021-02-11 17:39:43
问题 I am trying to sum the unit value by date, and create a new array where there are no duplicate dates. For example, I want to calculate the total of 2015-12-04 00:01:00 . This date has occurred 2 times in the following data, its value is 5 and 6 , which is going to be: [{date: '2015-12-04 00:01:00', unit: 11}, ... etc] I have tried arr = results.map(x => x.unit).reduce((a,c) => a + c) but it only return a single value, not an array. results = [ { unit: 5, date: '2015-12-04 00:01:00' }, { unit:

Writing an array to a file in C

丶灬走出姿态 提交于 2021-02-11 17:25:30
问题 I am attempting to write an array of the first N primes to a txt file in rows of 5 entries each, with 10 spaces between each entry. The relevant code is as follows: #include<stdio.h> #include<math.h> #define N 1000 ... void writePrimesToFile(int p[N], char filename[80]) { int i; FILE *fp = fopen(filename, "w"); for(i = 0; i<=N-1; i++) { for(i = 0; i<5; i++) { fprintf(filename, "%10%i", p[i]); } printf("/n"); fclose(fp); } printf("Writing array of primes to file.\n"); } The compiler throws the