array

Flatten a nested array of objects over a array field

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Have an object a1 = [{name:'x',age:21, addr:[{flat:1,add:'xyz'},{flat:2,add:'xsr'}]}, {name:'y',age:22, addr:[{flat:3,add:'xyz1'},{flat:4,add:'xsr1'}]] Desired output: [{name:'x',age:21, addr:{flat:1,add:'xyz'}}, {name:'x',age:21, addr:{flat:2,add:'xsr'}}, {name:'y',age:22, addr:{flat:3,add:'xyz1'}, {name:'y',age:22, addr:{flat:4,add:'xsr1'}] Please suggest! I am trying to accomplish this using lodash/underscore. 回答1: Map every item in the original array to a new array, with a number of items according to the number of addr fields. Using

Convert a string of numbers into an array

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i'm having problems creating a program that converts a string of numbers into an array. i know there is a similar question on here, but all i have to work with is a set of numbers such as [10 15 16 0 57 438 57 18] heres what i have so far: import java.util.Scanner; public class Histogram { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String numbers; numbers = keyboard.next(); System.out.println(numbers); int [] n1 = new int [numbers.length()]; for(int n = 0; n < numbers.length(); n++) { n1[n] = Integer

Laravel - must be of the type array, none given

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Having a strange problem with my laravel 5.2 build, I'm trying to send data from a form to my database and for some reason an error keeps being thrown on submit which states "Argument 1 passed to App\Http\Controllers\PostsController::postStatus() must be of the type array, none given" and I'm not sure why as I am sending data into an array. My code is shown below. timeline.blade.php @extends('layouts.app') @section ( 'content' ) < div class = "container-fluid" > < div class = "row" > < div class = "col-md-2" > < div class = "row

pulling unique values from an array of custom objects

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i have an array list of custom objects. each object contains a value i need to pull out, claimNO, but is not a unique value, meaning say 5 objects may have the same claimNO. what i need to do is make an array that only has unique claimNO's. i need to display this in a picker and can't have any repeating claimNO. my object: @interface ClaimCenterClaim : NSObject { NSNumber *claimID; NSString *claimNO; NSNumber *coid; NSString *eventDates; } @property (nonatomic, retain) NSNumber *claimID; @property (nonatomic, retain) NSString *claimNO;

PHP: Extract value from JSON array

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an API that takes parameters from a post through JSON and I want to extract one of the values in an array for a key value pair. However, despite many attempts, I can't get it to work. Here is my code: $json = file_get_contents('php://input'); $request = json_decode($json, true); $parameters = $request["result"]["parameters"]; When I log $parameters to a text file, it log as {"numberofhits":"5"} However, my efforts to capture the value 5 are not working: $numhits = $json['numberofhits']; logs as empty. So does: $numhits = $parameters-

Load multidimensional VBA Array from disk

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to save and then load a multi-dimensional VBA array to/from disk. According to the MSDN website , the number of dimensions are saved as a descriptor in the file, but I can't figure out how to access/load them. The example below works, but only because I have hard coded the array dimensions. The commented out line works in a dynamic sense, but the array's dimensions are lost in the process. Here's some sample code: Sub WriteArray () Dim file_name As String Dim file_length As Long Dim fnum As Integer Dim values () As

Calculate euclidean distance with numpy

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a point set which I have stored its coordinates in three different arrays (xa, ya, za). Now, I want to calculate the euclidean distance between each point of this point set (xa[0], ya[0], za[0] and so on) with all the points of an another point set (xb, yb, zb) and every time store the minimum distance in a new array. Let's say that xa.shape = (11,), ya.shape = (11,), za.shape= (11,). Respectively, xb.shape = (13,), yb.shape = (13,), zb.shape = (13,). What I want to do is to take each time one xa[],ya[],za[], and calculate

JavaScript - extremely confused on removing elements from Container

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm making a 2D, top-down Zelda style web rpg single player in JavaScript. When the player (purple shirt) walks near a cat, it will "rescue" it... which basically removes the animalContainer from the ContainerOfAnimals (thereby removing animalContainer's BMP from the stage), and then add the id of that animalContainer to a rescuedTotal_Array ... The weird thing is, In the pic below, I'm able to rescue animalContainer2 and then rescue animalContainer1 ... But if I go from animalContainer1 to animalContainer2 , it throws a Uncaught TypeError:

Iteration over numeric Array in javascript returns strings

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Why for (i in [1, 2, 3]) console.log(typeof(i), i); gives this: [Log] string 0 [Log] string 1 [Log] string 2 I've expected numbers. @ Safari 7.0 (9537.71), Mac OS X 10.9 回答1: That is because an Array in Javascript is a special Object with property keys (which are strings) used as indices. you are iterating that Array like an Object and because of that i is seen as a property key , a string. To iterate in the right way an Array you have to use the following: for( var i=0; i < [1,2,3].length; i++){ ... } 回答2: Try instead : var arr = [1, 2, 3];

Variable name as variable

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a question about using variables as variablename. I have an array with database fieldnames as key and object properties as values like this: $properties = array("userid" => "user['userid']", "city" => "hometown"); foreach ($properties as $field => $property ) { $value1 = $db->$field; $value2 = $obj->$property; } This works for the property hometown but doesn't work voor de property user['userid']. What is the correct way to adress the property variable? I also tried several things like: ${property} or {$property} but without luck yet.