array

Javascript - Pop a value from array, but not at the end of array

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have for example this array (each number is singolar, no one duplicate) called pvalue : 1 2 3 15 20 12 14 18 7 8 (sizeof 10). I need for example to pop the value "15", and after this pvalue should be 1 2 3 20 12 14 18 7 8 (sizeof 9). How can do it? the pop() function take the value at the end of the array. I don't want this :) cheers EDIT for(i=0; i<pvalue.length; i++) { if(pvalue[i]==param) { ind=i; break; } } pvalue.splice(ind, 1); 回答1: You're looking for splice . Example: http://jsbin.com/oteme3 : var a, b; a = [1, 2, 3, 15, 20, 12, 14,

Repeat array to a certain length?

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm having an array for example with 4 elements array("a", "b", "c", d"); what is the fastest way to repeat this array to create a new array with a certain length, e.g 71 elements? 回答1: // the variables $array = array("a", "b", "c", "d"); $desiredLength = 71; $newArray = array(); // create a new array with AT LEAST the desired number of elements by joining the array at the end of the new array while(count($newArray) <= $desiredLength){ $newArray = array_merge($newArray, $array); } // reduce the new array to the desired length (as there might

Print arrays in Java

匿名 (未验证) 提交于 2019-12-03 08:42:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm writing a method that prints every Object it get passed. This works fine by calling the Object.toString() method for the object but doesn't works for arrays. I can find out whether it is an Array with the Object.getClass().isArray() method, but I don't know how to cast it. int[] a; Integer[] b; Object aObject = a; Object bObject = b; // this wouldn't work System.out.println(Arrays.toString(aObject)); System.out.println(Arrays.toString(bObject)); 回答1: If you don't know the type you can cast the object to Object[] and print it like this

How to cast from List&lt;Double&gt; to double[] in Java?

匿名 (未验证) 提交于 2019-12-03 08:42:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a variable like that: List frameList = new ArrayList (); /* Double elements has added to frameList */ How can I have a new variable has a type of double[] from that variable in Java with high performance? 回答1: High performance - every Double object wraps a single double value. If you want to store all these values into a double[] array, then you have to iterate over the collection of Double instances. A O(1) mapping is not possible, this should be the fastest you can get: double[] target = new double[doubles.size()]; for (int i = 0; i

Passing array via hidden fields to rails

匿名 (未验证) 提交于 2019-12-03 08:42:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i have a hidden_tag like this in my form <%= f.hidden_field :loc , {:multiple => true} %> which renders to <input id="business_loc" multiple="multiple" name="business[loc][]" type="hidden" style="color: rgb(175, 175, 175); " value=""> currently am setting the business_loc value as a comma seperated string hoping rails would recognize when submit the form. But this is the value i got on the server side "loc"=>["80.22167450000006,13.0454044"] instead "loc"=>[80.22167450000006,13.0454044] how do i set the correct value in hidden field, so rails

Difference between @[] and [NSArray arrayWithObjects:] [duplicate]

匿名 (未验证) 提交于 2019-12-03 08:42:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Possible Duplicate: Should I prefer to use literal syntax or constructors for creating dictionaries and arrays? Is there any difference between: NSArray *array = @[@"foo", @"bar"]; and NSArray *array = [NSArray arrayWithObjects:@"foo", @"bar", nil]; Is one of those more stable, faster, or anything else? 回答1: This documentation doesn't mention anything about efficiency directly, but does mention that NSArray *array = @[@"foo", @"bar"]; is equivalent to NSString *strings[3]; strings[0] = @"foo"; strings[1] = @"bar"; NSArray *array = [NSArray

Is an array argument passed to a function not a constant pointer?

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Consider the code: void foo(char a[]){ a++; // works fine, gets compiled //... } Now, consider this: void foo(){ char a[50]; a++; // Compiler error //... } I heard an array is equivalent to a constant pointer and can't be incremented as it is not a lvalue... Then why does first code gets compiled, is it so because array arguments to functions are passed as a pointer, i.e. T[] is converted to T* for passing.. So, foo(a) passes a as a pointer. But is it not back converted to T[] again because is declared as: void foo(char a[]); 回答1: When you

How to check if the JSON data is one object or an array of objects?

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I got server responsed JSON data: var data = SERVER_RESPONSE; this data could be an object {id: 12, name: John} , it could also be an array of objects [{id: 12, name: John}, {id: 22, name: OMG}] In Javascript, how can I check if the JSON data is one object or an array of objects? 回答1: You could use the following test: if (data instanceof Array) { // data is an array } else { // it is not an array } 回答2: A simple test is to check for the existence of obj.length and obj[0] . It's not 100% fool proof, but if you know that your data can only

Deserialization of an array always gives an array of nulls

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a custom abstract base class with sub classes that I've made serializable/deseriablizeable with ISerializable. When I do serialization/deserialization of single instances of this class' sub classes, everything works fine. However, when I do an array of them I always end up with an array of nulls on deserialization. Serialization is done with BinaryFormatter. The items are contained within a: public ObservableCollection<Trade> Trades { get; private set; } On serialization this is done in GetObjectData on the SerializationInfo parameter

Array as a struct field

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I would like to create a non binary tree structure in Rust. Here is a try struct TreeNode<T> { tag : T, father : Weak<TreeNode<T>>, childrenlists : [Rc<TreeNode<T>>] } Unfortunately, this does not compile. main.rs:4:1: 8:2 error: the trait `core::marker::Sized` is not implemented for the type `[alloc::rc::Rc<TreeNode<T>>]` [E0277] main.rs:4 struct TreeNode<T> { main.rs:5 tag : T, main.rs:6 father : Weak<TreeNode<T>>, main.rs:7 childrenlist : [Rc<TreeNode<T>>] main.rs:8 } main.rs:4:1: 8:2 note: `[alloc::rc::Rc<TreeNode<T>>]` does not have a