arrays

How do I return an array with the initial letters of all the objects in another array?

I am working on converting a plain tableview to a sectioned tableview. I would like the section titles to be the first letter for the items in the section. This is what I have so far in my titleForHeaderInSection method: NSSortDescriptor *sortDescriptor; sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"Name" asce...

C++: 2D arrays vs. 1D array differences

I have an array of float rtmp1[NMAX * 3][3], and it is used as rtmp1[i][n], where n is from 0 to 2, and i is from 0 to 3 * NMAX - 1. However, I would like to convert rtmp1 to be rtmp1[3 * 3 * NMAX]. Would addressing this new 1D array as rtmp1[3 * i + n] be equivalent to rtmp1[i][n]? Thanks in advance for the clarifications. ...

Array Allocation Subscript Number

Quick question regarding how memory is allocated. If someone were to allocate 20 chars like this: char store[20]; does this mean that it allocated 20 char type blocks of memory, or that it allocated char type blocks of memory starting with 0 and ending with 20. The difference is that the first example's range would be from store[0] t...

How to check if an element in one multi-dimensional Ruby array exists in another?

I am trying to determine if the an element in one multi-dimensional array exists in another similarly structured array. suspects = [['Rod', 100], ['Jane', 75], ['Freddy', 125]] criminals = [['Bill', 75], ['Ted', 50], ['Rod', 75]] The response I am looking for is either true or false. In the example above the response would be true bec...

Nested foreach()

I have the following array: Array ( [1] => Array ( [spubid] => A00319 [sentered_by] => pubs_batchadd.php [sarticle] => Lateral mixing of the waters of the Orinoco, Atabapo [spublication] => Acta Cientifica Venezolana [stags] => acta,confluence,orinoco,rivers,venezuela,waters [authors] => Array ( [1] =...

How to use Java Collections.shuffle() on a Scala array?

I have an array that I want to permutate randomly. In Java, there is a method Collections.shuffle() that can shuffle the elements of a List randomly. It can be used on an array too: String[] array = new String[]{"a", "b", "c"}; // Shuffle the array; works because the list returned by Arrays.asList() is backed by the array Collections.s...

Tricky transform of hash -> array

I have a structure like this: {:foo => ['foo1', 'foo2'], :bar => ['bar1']} Which I would like to have transformed into: [[:foo, "foo1"], [:foo, "foo2"], [:bar, "bar1"]] My current solution is imperative: result = [] h.each do |k,v| v.each do |value| result << [k, value] end end While this works, I am certain that there i...

php return only duplicated entries from an array

i want to retrieve all duplicated entries from a array, how can it be possible in php. array(1=>'1233',2=>'12334',3 =>'Hello' ,4=>'hello', 5=>'U'); i want to return an array having hello out put array array(1 =>'Hello' ,2=>'hello'); ...

JS looping and populating array. Which is faster?

I just saw a video of Nicholas Zakas of Yahoo, at GoogleTalks talking about speeding up your website. One of the things he mentioned was doing loops in reverse order to skip one of two comparisons: for (i = len; i--;) {} And he said to keep away from JS libraries implementations of for each. Just for fun I thought I'd try it out. Turns ...

How do I access Collection keys during For Each in VB.net ?

I have some code like this: Dim col As Collection = New Collection col.Add(value1, "key1") col.Add(value2, "key2") ' later... For Each item As String In col ' want to get valueX and keyX here; currently, "item" holds the value Next How can I get both the value and key within the loop? Maybe there is another class that makes this ...

Is there a constraint, interface or class that envelops IEnumerable or array?

I'd like to take the following if possible and combine them: public static T[] ForEach<T>(this T[] TArray, Action<T> doWhat) { foreach (var item in TArray) { doWhat(item); } return TArray; } The above handles array, below handles lists public static IEnumerable<T> ForEach<T>(this IEnumerable<T> TList, Action<T> action) ...

PHP: What causes: "Notice: Uninitialized string offset" to appear?

Hello, I have a form that users fill out, on the form there are multiple identical fields, like "project name", "project date", "catagory", etc. Based on how many forms a user is submitting: My goal is to: loop over the number of forms create individual SQL insert statements However, PHP throws me a NOTICE that I don't seem to under...

Best way to grab an array of dictionaries from a plist and create sections based on the values for a key.

I have a plist that contains an array with a collection of dictionaries. The dictionaries in the array are used to create a fairly complex tableview with 2 images and 2 lines of text in each cell. I am wanting to create sections in the tableview based on the first letter for the value corresponding to the "MainText" key. Here is the p...

Access array returned from a function - javascript/jquery noob moment

When the form is submitted, I'm calling a function getPosts and passing through a variable str. What I'd like to do is get the data returned from that function. // when the form is submitted $('form#getSome').submit(function(){ var str = $("form#getSome").serialize(); var something = getPosts(str); * This is where I'd like to g...

Why would setting an element in an array and unsetting then setting an element in an array be different? PHP

Under what circumstances would $array[$index] = $element; and unset($array[$index]); $array[$index] = $element; be different? Assuming I am not using any references in my array, are these logically equivalent? ...

Does PHP have an equivalent to Python's list comprehension syntax?

Python has syntactically sweet list comprehensions: S = [x**2 for x in range(10)] print S; [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] In PHP I would need to do some looping: $output = array(); $Nums = range(0,9); foreach ($Nums as $num) { $out[] = $num*=$num; } print_r($out); to get: Array ( [0] => 0 [1] => 1 [2] => 4 ...

Is there a cleaner way to initialise this generic array?

Yesterday I attempted to create an array of objects, belonging to a non-static inner class of a generic class. It seems that there is no nice way of doing so. First attempt: public class Wibble<T>{ public static void main(String...args){ new Wibble<String>(); } public Wibble(){ Bar...

Using My.Settings to save an array in VB

How do you save an array or an arraylist in vb.net using My.Settings? I cannot find the array type anywhere, even in the browse window. I absolutely need to be able to save this. I know I can convert the array to a string, but I do not know how to convert a string to an array. I know that if I were to break it at a delimiter then I c...

Error passing 2D char* array into a function.

I'm trying to pass a 2D array of char* into a function. I am getting this error: "cannot convert 'char* (*)[2]' to 'char***' for argument '1' to 'int foo(char***)'" Code: int foo(char*** hi) { ... } int main() { char* bar[10][10]; return foo(bar); } ...

How to create an array from a CSV file using PHP and the fgetcsv function

Can someone kindly provide a code to create an array from a CSV file using fgetcsv? I've used the following code to create an array from a simple CSV file, but it doesn't work right when one of my fields has multiple commas - such as addresses. $lines =file('CSV Address.csv'); foreach($lines as $data) { list($name[],$address[],$status...