arrays

javaScript filter nested objects and arrays

大城市里の小女人 提交于 2021-02-19 05:56:05
问题 My use case is something like this. I have an array that has an object. That each object has an array called menu Again that menu array has objected. That each object has an array dish_has_categories In dish_has_categories array, if there is an object with CategoryId is equal to 8 I want to filter out that root object. My original data object const data = [{ menuName: "Hot dogs", menu: [ { dishId: '1', dish_has_categories: [{ CategoryId: '8' }] }, { dishId: '2', dish_has_categories: [{

php - sort array by custom criteria

此生再无相见时 提交于 2021-02-19 05:42:30
问题 I have an array of objects: object1-> name="Name1" key="key1" object2-> name="Name2" key="key2" object3-> name="Name3" key="key3" and an array of priority keys: $keys = ["key3", "key1"]; I need to sort the array of objects based on priority keys, so the result should be: object3: name="Name3" key="key3" object1-> name="Name1" key="key1" object2: name="Name2" key="key2" What is the best way to do it? 回答1: The idea is to add a priority as integer, and sort the array from the highest integer to

Select and sort a column in a table using Javascript

情到浓时终转凉″ 提交于 2021-02-19 05:40:06
问题 I want to select a particular column of a table and sort it accordingly using Javascript (No frameworks or plugins). Could anyone help me regarding this? <table> <thead> <tr> <td>Col1</td> <td>Col2</td> <td>Col3</td> <td>Col4</td> </tr> </thead> <tbody> <tr> <td>Data11</td> <td>Data23</td> <td>Data53</td> <td>Data45</td> </tr> <tr> <td>Data81</td> <td>Data42</td> <td>Data33</td> <td>Data4854</td> </tr> <tr> <td>Data84681</td> <td>Data452</td> <td>Data354</td> <td>Data448</td> </tr> <tr> <td

Create weighted igraph Graph from numpy summetric 2D array as adjacency matrix

陌路散爱 提交于 2021-02-19 05:36:12
问题 I am having a numpy 2D array, with the values representing the weights of edges between nodes. The matrix is symmetric, and I take the diagonal to be zero. I don't find an example of how to convert this matrix into igraph Graph object. I've tried the following approach, but it doesn't work: import numpy as np import igraph def symmetrize(a): return a + a.T - 2*np.diag(a.diagonal()) A = symmetrize(np.random.random((100,100))) G = igraph.Graph.Adjacency(A.tolist()) 回答1: Use Graph.Weighted

Filter array in array and get only the filtered items

a 夏天 提交于 2021-02-19 05:35:11
问题 I have the following array named filters and try to filter it by selected items. At the end I want to have all filters where a selected item is, but only with the selected items let filters = [ { id: 0, name: 'property', items: [ { id: 0, name: 'x', isSelected: false }, { id: 1, name: 'y', isSelected: true } ] }, { id: 1, name: 'property2', items: [ { id: 0, name: 'x', isSelected: true }, { id: 1, name: 'y', isSelected: false } ] } ] I want to get the following array at the end: let

jQuery - Append to the multiple dropdowns for matching array keys as class name

安稳与你 提交于 2021-02-19 05:27:45
问题 var obj: {1: Array(1), 2: Array(1), 5: Array(3), 6: Array(3), 27: Array(2)} 1: ["BC8907"] 2: ["B6789"] 5: (3) ["H67890", "BC567", "BC8907"] 6: (3) ["BH123", "BH1234", "BM2345"] 27: (2) ["EPC123", "EPC1234"] As you can see from the above array, there are five keys(1,2,5,6,27). I have a set of select tags in the DOM, with any one of the array key as class name. I'm trying to append values to all the dropdowns as options for the matching key as class names . For example: <select name="hno[]"

jQuery - Append to the multiple dropdowns for matching array keys as class name

ε祈祈猫儿з 提交于 2021-02-19 05:27:43
问题 var obj: {1: Array(1), 2: Array(1), 5: Array(3), 6: Array(3), 27: Array(2)} 1: ["BC8907"] 2: ["B6789"] 5: (3) ["H67890", "BC567", "BC8907"] 6: (3) ["BH123", "BH1234", "BM2345"] 27: (2) ["EPC123", "EPC1234"] As you can see from the above array, there are five keys(1,2,5,6,27). I have a set of select tags in the DOM, with any one of the array key as class name. I'm trying to append values to all the dropdowns as options for the matching key as class names . For example: <select name="hno[]"

jQuery - Append to the multiple dropdowns for matching array keys as class name

戏子无情 提交于 2021-02-19 05:27:43
问题 var obj: {1: Array(1), 2: Array(1), 5: Array(3), 6: Array(3), 27: Array(2)} 1: ["BC8907"] 2: ["B6789"] 5: (3) ["H67890", "BC567", "BC8907"] 6: (3) ["BH123", "BH1234", "BM2345"] 27: (2) ["EPC123", "EPC1234"] As you can see from the above array, there are five keys(1,2,5,6,27). I have a set of select tags in the DOM, with any one of the array key as class name. I'm trying to append values to all the dropdowns as options for the matching key as class names . For example: <select name="hno[]"

sscanf usage on matrix of unknown size?

此生再无相见时 提交于 2021-02-19 05:26:16
问题 So, I have a file that contains a matrix of NxM size. For example: P2 3 3 1 1 0 0 0 1 0 0 0 1 The 'P2' is just an useless indicator, the first '3' indicates how many columns are and the second '3' indicates how many lines, '1' indicates the maximum value among the matrix's numbers. This matrix was stored in a data structure like this: typedef struct { int c; // columns int l; // lines unsigned char max; // max value unsigned char** data // variable to store matrix's numbers } Matrix; To store

Find all floats or ints in a given string

谁说胖子不能爱 提交于 2021-02-19 05:10:21
问题 Given a string, "Hello4.2this.is random 24 text42" , I want to return all ints or floats, [4.2, 24, 42] . All the other questions have solutions that return just 24. I want to return a float even if non-digit characters are next to the number. Since I am new to Python, I am trying to avoid regex or other complicated imports. I have no idea how to start. Please help. Here are some research attempts: Python: Extract numbers from a string, this didn't work since it doesn't recognize 4.2 and 42.