arrays

Check if an array contains elements of another array in swift

半腔热情 提交于 2021-02-17 04:46:12
问题 I need to check if an array contains at least one or more elements of another array and print them out in swift. This is my situation: var array1 = ["user1", "user2", "user3", "user4"] var array2 = ["user3, "user5", "user7", "user9, "user4"] //I need to get back an array that says that both the arrays contains ex. "user3" and "user4" I searched the web but i only found the opposite answer that helps t check if there is a difference between 2 arrays using array.symmetricDifference() Any helps?

How to group objects in an array and sort them depending on an object property

强颜欢笑 提交于 2021-02-17 04:30:53
问题 groupSelectedQuestions(selectedQuestions){ var questions = [ { q: 'why?', group: 'no-group', date: '1' }, { q: 'what?', group: 'group 1', date: '1' }, { q: 'when?', group: 'group 2', date: '2' }, { q: 'where?', group: 'group 1', date: '2' }, { q: 'which', group: 'group 2', date: '3' } ], result = questions.reduce(function (r, a) { r[a.group] = r[a.group] || []; r[a.group].push(a); return r; }, {}); /** more code here. Here I would put if statements that check for all condtions I have stated

Numpy reshape an array with specific order

人盡茶涼 提交于 2021-02-17 04:26:25
问题 Let's say I have this array x: x = array([1, 2, 3, 4, 5, 6, 7, 8]) x.shape = (8,1) I want to reshape it to become array([[1, 3, 5, 7], [2, 4, 6, 8]]) this is a reshape(2, 4) on x but in the straight forward way: y = x.reshape(2,4) y becomes array([[1, 2, 3, 4], [5, 6, 7, 8]]) and that's not what I want. Is there a way to transform the array in that specific way? 回答1: In[4]: x.reshape(4, 2).T Out[4]: array([[1, 3, 5, 7], [2, 4, 6, 8]]) 回答2: The easiest way to do this is to specify the order

JavaScript flatten nested array

一个人想着一个人 提交于 2021-02-17 03:41:10
问题 I am trying to flatten any length of a nested array into a single array. Why it's showing array rather than array value? function flatten(arr) { var res = []; for (var i = 0; i < arr.length; i++) { if (toString.call(arr[i]) === "[object Array]") { res.push(flatten(arr[i])); } else { res.push(arr[i]); } } return res; } console.log(flatten([1, 2, [3, [4, 5, [6]]], 7, 8])); // [1, 2, Array(2), 7, 8] 回答1: You are pushing to res the result of flatten , which is an array. Instead Array#concat the

JavaScript flatten nested array

谁说胖子不能爱 提交于 2021-02-17 03:38:09
问题 I am trying to flatten any length of a nested array into a single array. Why it's showing array rather than array value? function flatten(arr) { var res = []; for (var i = 0; i < arr.length; i++) { if (toString.call(arr[i]) === "[object Array]") { res.push(flatten(arr[i])); } else { res.push(arr[i]); } } return res; } console.log(flatten([1, 2, [3, [4, 5, [6]]], 7, 8])); // [1, 2, Array(2), 7, 8] 回答1: You are pushing to res the result of flatten , which is an array. Instead Array#concat the

How could I separate each JSON object and group them to an array in JavaScript?

﹥>﹥吖頭↗ 提交于 2021-02-17 03:31:48
问题 example of req.files from multer.js [ { fieldname: files0, originalname: 'Screenshot from 2020-05-23 01-52-30.png', encoding: '7bit', mimetype: 'image/png', destination: 'public/uploads/projects/0a480789-eb14-4fe4-bb89-44aa741efe33/proposals/chma00000133', filename: '1606822252923_Screenshot from 2020-05-23 01-52-30.png', path: 'public/uploads/projects/0a480789-eb14-4fe4-bb89-44aa741efe33/proposals/chma00000133/1606822252923_Screenshot from 2020-05-23 01-52-30.png', size: 172092 }, {

How could I separate each JSON object and group them to an array in JavaScript?

跟風遠走 提交于 2021-02-17 03:31:17
问题 example of req.files from multer.js [ { fieldname: files0, originalname: 'Screenshot from 2020-05-23 01-52-30.png', encoding: '7bit', mimetype: 'image/png', destination: 'public/uploads/projects/0a480789-eb14-4fe4-bb89-44aa741efe33/proposals/chma00000133', filename: '1606822252923_Screenshot from 2020-05-23 01-52-30.png', path: 'public/uploads/projects/0a480789-eb14-4fe4-bb89-44aa741efe33/proposals/chma00000133/1606822252923_Screenshot from 2020-05-23 01-52-30.png', size: 172092 }, {

initialize array with stackoverflow error [duplicate]

这一生的挚爱 提交于 2021-02-17 03:30:20
问题 This question already has answers here : How to overcome Stack Size issue with Visual Studio (running C codes with big array) (3 answers) Closed 2 years ago . I have simple method: void loadContent() { int test[500000]; test[0] = 1; } when I call this method, this error occurs: Unhandled exception at 0x00007FF639E80458 in RasterizeEditor.exe: 0xC00000FD: Stack overflow (parameters: 0x0000000000000001, 0x000000AE11EB3000). I changed the arraysize to 100 and everything is working fine... but I

initialize array with stackoverflow error [duplicate]

我与影子孤独终老i 提交于 2021-02-17 03:30:17
问题 This question already has answers here : How to overcome Stack Size issue with Visual Studio (running C codes with big array) (3 answers) Closed 2 years ago . I have simple method: void loadContent() { int test[500000]; test[0] = 1; } when I call this method, this error occurs: Unhandled exception at 0x00007FF639E80458 in RasterizeEditor.exe: 0xC00000FD: Stack overflow (parameters: 0x0000000000000001, 0x000000AE11EB3000). I changed the arraysize to 100 and everything is working fine... but I

Read matrix to 2D array in C/C++

隐身守侯 提交于 2021-02-17 03:17:43
问题 What is the simplest way to read/input a matrix of numbers into an array in C++? This is the file content (dimensions are unknown): 283 278 284 290 290 286 273 266 266 266 261 252 246 382 380 379 381 382 379 384 387 385 382 376 365 357 285 282 281 279 276 273 272 264 255 255 247 243 237 196 190 186 183 183 180 179 186 191 195 195 188 187 245 237 226 220 221 222 225 228 234 245 252 264 272 283 278 284 290 290 286 273 266 266 266 261 252 246 I've tried a lot of suggested codes, but non of them