arrays

Best way to query back unique attribute values in a javascript array of objects?

What would be the best (or fastest) way to find all the possible values of "foo" in the following example array. var table = [ {foo: 0, bar:"htns", stuff:123}, {foo: 2, bar:"snhn", stuff:156}, {foo: 5, bar:"trltw", stuff:45}, {foo: 5, bar:"lrctm", stuff:564}, //few thousand lines later {foo: 2596, bar:"cns", stuf...

Why can some arrays be published but not others?

type TStaticArray = array[1..10] of integer; TDynamicArray = array of integer; TMyClass = class(TObject) private FStaticArray: TStaticArray; FDynamicArray: TDynamicArray; published property staticArray: TStaticArray read FStaticArray write FStaticArray; //compiler chokes on this property dynamicArr...

Why does "int[] is uint[] == true" in C#

Can somebody clarify the C# is keyword please. In particular these 2 questions: Q1) line 5; Why does this return true? Q2) line 7; Why no cast exception? public void Test() { object intArray = new int[] { -100, -200 }; if (intArray is uint[]) //why does this return true? { uint[] uintArray = (uint[])in...

When would you use an array rather than a vector/string?

I'm a beginner C++ programmer and so I've learnt using arrays rather than vectors (this seems to be the general way to do things, then move on to vectors later on). I've noticed that a lot of answers on SO suggest using vectors over arrays, and strings over char arrays. It seems that this is the "proper" way to code in C++. That all be...

How to sort a date array in PHP

I have an array in this format: Array ( [0] => Array ( [28th February, 2009] => 'bla' ) [1] => Array ( [19th March, 2009] => 'bla' ) [2] => Array ( [5th April, 2009] => 'bla' ) [3] => Array ( [19th April, 2009] => '...

How do I implement operator[] for dynamic array?

I have a need to implement dynamic array by myself to use it in simple memory manager. struct Block { int* offset; bool used; int size; Block(int* off=NULL, bool isUsed=false, int sz=0): offset(off), used(isUsed), size(sz) {} Block(const Block& b): offset(b.offset), used(b.used), size(b.size) {} }; class BlockList ...

Array of an unknown length in C#

I've just started learning C# and in the introduction to arrays they showed how to establish a variable as an array but is seems that one must specify the length of the array at assignment, so what if I don't know the length of the array? ...

Having PHP receive the days you're available without tons of variables

Here's my situation: I'm building a small website where, when registring, you can select which days you're available for something. Mondaymorning Mondayafternoon Tuesdaymorning Tuesdayafternoon etc... All the way to sundayafternoon. I'm formchecking this offcourse, in PHP, and I need to declare 14 variables and go over each one to det...

How to pull out strings from array on iPhone?

I want to pull out a string from an array by index. e.g array with object: @"Hello", @"World" How to get @"World" from it? I use array[1], but it seems not work. ...

Array of Strings to an Array of Objects

Maybe there is a method that does this that I don't know about - I doubt it though - but I'm trying to convert an array of strings to an array of Objects. Here is the problem: I'm reading a file in from the command line. The file represents several classes of the following types each with their own data fields. Vehicle is the parent clas...

What does it mean to pre-increment $#array?

I've come across the following line of code. It has issues: it is intended to do the same as push it ought to have used push it's hard to read, understand I've since changed it to use push it does something I thought was illegal, but clearly isn't here it is: $array [++$#array] = 'data'; My question is: what does it mean to pre-i...

How can I "filter" JSON for unique key name/value pairs?

I've got some JSON data that is giving me a list of languages with info like lat/lng, etc. It also contains a group value that I'm using for icons--and I want to build a legend with it. The JSON looks something like this: {"markers":[{"language":"Hungarian","group":"a", "value":"yes"}, {"language":"English", "group":"a", "value":"yes"},...

Boolean[] vs. BitSet: Which is more efficient?

What is more efficient in terms of memory and CPU usage — an array of booleans or a BitSet? Specific BitSet methods are not used, only get/set/clear (==, =, Arrays.fill respectively for an array). ...

how to find if an arraylist is single dimensional or multi dimensional in C#.!?

hi, In C#, i have created ArrayList using structures. so it creates multi dimensional array list. public struct ParameterValues { public ArrayList al; }; ArrayList alCombined = new ArrayList(); for(int i=0; i < CONDITION , i++) alCombined.Add(obj.pValue.al); The dimension of ArrayList alCombined depends on the CONDIT...

How do I access an individual character from an array of strings in c?

Just trying to understand how to address a single character in an array of strings. Also, this of course will allow me to understand pointers to pointers subscripting in general. If I have char **a and I want to reach the 3rd character of the 2nd string, does this work: **((a+1)+2)? Seems like it should... ...

C Arrays and unbroken lists

/edit: thanks for the help so far, however I haven't got any of the solutions to take the sample input and give the sample output. My description isn't the clearest, sorry. I have an array composed of binary data. What I want to do is determine how long each unbroken segment of 1s or 0s is. Say I have this data: 0111010001110 In an ...

Initializing an array of pointers to pointers

This example works fine: static char *daytab[] = { "hello", "world" }; This doesn't: static char *daytab[] = { {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} }; The way I see it is that the first example creates an array that is filled with pointers to the tw...

passing char buffer to functions and getting the size of the buffer

Hello, I have set the buffer to size 100. I display the buffer in the main function where the buffer is declared. However, when I pass the buffer to the function and get the sizeof '4', I was thinking it should be 100, as that is the size of the buffer that I created in main. output: buffer size: 100 sizeof(buffer): 4 #inc...

What's the best way to get the last N elements of a Perl array?

What's the best way to get the last N elements of a Perl array? If the array has less than N, I don't want a bunch of undefs in the return value. ...

How do I best process my multi-dimensional arrays in PHP?

I have an app that shows store sales. It is a multi-dimensional array, so each value in the root array is an array containing [sales], [cost], [date], etc. for the given day it pertains to. OK, there are 2 arrays for each store. One is for verified numbers and the next is for unverified numbers. The unverified picks up right after the ve...