arrays

How might I extract the property values of a JavaScript object into an array?

Given a JavaScript object: var dataObject = { object1: {id: 1, name: "Fred"}, object2: {id: 2, name: "Wilma"}, object3: {id: 3, name: "Pebbles"} }; How do I efficiently extract the inner objects into an array? I do not need to maintain a handle on the object[n] IDs. var dataArray = [ {id: 1, name: "Fred"}, {id: ...

array of pointers as function parameter

I have a basic question on array and pointer in C/C++. Say I have: Foo* fooPtrArray[4]; How to pass the fooPtrArray into a function? I have tried: int getResult(Foo** fooPtrArray){} // failed int getResult(Foo* fooPtrArray[]){} // failed How can I deal with pointer array? EDIT: I once thought the error msg is from passing the...

Just Want to know what this error message really means!

expected unqualified-id before '{' Where is this error on my code? Thanks everyone! #include <iostream> using std::cout; using std::endl; //function prototypes void findsmallest (int[], int &); void findsmallest (int scores [], int & min); int main() { //declare variables int smallest = 0; int scores[20] = { 90, 54...

Matching a string against a list of words

Say I have the string "i zipped the fezz and it blipped like a baa" and I have an array of words (moo, baa, zip, fjezz, blaa) that I wanted to test to see it they're contained in the string, is there a way of doing so without either using | in the regex or iterating over each word? TIA ...

Ruby: OOP & two-dim array question

I need to create a two-dimensional array Class. I've done a work, but discovered that my class simply has an inner two-dim array, and to access the elements I have to write a redundant word 'table': class Table attr_accessor :table def initialize(w,h) @table = Array.new(h) h.times do @table << Array.new(w) end end x = Ta...

Implement an array of stacks in C

Implement an array of stacks where stacks are defined : typedef struct StackNode { int data; StackNode* next; } StackNode; Each array element points to a stack, each stack is initialized as an empty stack. When you start adding elements it will start adding them to the stack in Stacks[0]; if you say -2 in stdin and then 4 for...

Ruby: two dimensional array

I wonder if there's a possibility to create a two dimensional array and to quickly access any horizontal or vertical sub array in it? Ok, I believe we can access a horizontal sub array in the following case: x = Array.new(10) 10.times do x << Array.new(20) x[6][3..8] = 'something' But as far as I understand, we cannot access like thi...

c++ array access through pointer

A simple question about accessing array information through pointers that I can't seem to figure out. I'm passing a bunch of multi-dimentional arrays into a function. Now they are not dynamic but even if static, I have to pass them as pointers right? (If I'm wrong, please do correct me) So once I do pass them into a function, how do I a...

PHP transform array from one dimenson to two

Hi, some "simple" problem: I've this array; $myArray = array( 'FOO', 'BAR, ); i want : $mayArray = array( 'FOO' => array(), 'BAR' => array(), ); in the moment iam doing it with an foreach: foreach ($myArray as $key => $val) { $newArray[$val] = array(); } $myArray = $newArray; is there an easyer way ? ;-) ...

PHP create 3D Array from Array with 3 Values

Hi, again me: following array; $myArray = array('FOO', 'BAR', 'HELLO'); i need: $myArray['FOO']['BAR']['HELLO'] = 0; any ideas? ...

What is the fastest or most elegant way to compute a set difference using Javascript arrays?

Let A and B be two sets. I'm looking for really fast or elegant ways to compute the set difference (A - B or A \B, depending on your preference) between them. The two sets are stored and manipulated as Javascript arrays, as the title says. Notes: Gecko-specific tricks are okay I'd prefer sticking to native functions (but I am open to ...

How to split a string into a List<string> from a multi-line TextBox that adds '\n\r' as line endings?

I've got a textbox in my XAML file: <TextBox VerticalScrollBarVisibility="Visible" AcceptsReturn="True" Width="400" Height="100" Margin="0 0 0 10" Text="{Binding ItemTypeDefinitionScript}" HorizontalAlignment="Left"/> with which I get a st...

Invalid Argument When Using String Array

Hello, I'm building a program that uses a WriteAllLines generic function: private static void WriteAllLines(string file, string[] contents) { using (StreamWriter writer = new StreamWriter(file)) { foreach (string line in contents) { writer.Write(line); } } } But the problem is that when...

MATLAB: Getting an array of cells from MATLAB to Java

I have an array created in MATLAB that contains a number of cell type objects which contain arrays of doubles. It's basically a <1xn cell> array and each cell is an array of doubles. What I want to do is to somehow export these so that I can then insert the data into Java as a ragged array of arrays of type int. Any thought on how to b...

String Array And a String Parameter

Hello, I"m developing a simple application that have a line like this: string[] values = ReadAll(inputFile); As inputFile is a string, but how I can do this without conflicts(Cannot implicitly convert type 'string' in 'string[]')? ...

Getting a text file into a two dimensional ragged array in Java.

Hey guys this is a followup to my previous question. I now have a text file which is formatted like this: 100 200 123 124 123 145 What I want to do is get these values into a two dimensional ragged array in Java. What I have so far is this: public String[][] readFile(String fileName) throws FileNotFoundException, IOException { ...

Problem with processing individual strings stored in an array of pointers to multiple strings in C

An array of pointers to strings is provided as the input. The task is to reverse each string stored in the input array of pointers. I've made a function called reverseString() which reverses the string passed to it. This functions works correctly as far as i know. The strings stored/referenced in the input array of pointers are sent on...

jquery .serializeArray(); add another value on top for passing to ajax

im doing following var data = $(form).serializeArray(); // now i want to add another value on this data data.username = 'this is username'; i want to know how can i add another value after doing serializeArray(), i tried all the things i know, but nothing is getting it to work. any ideas pls. ...

Returning array of data mapping values to parameters in python

I have a few functions that return an array of data corresponding to parameters ranges. Example: for a 2d array a, the a_{ij} value corresponds to the parameter set (param1_i, param2_j). How do I return the result and keep the parameter-value correspondence? Calling the function for each and every of param1_i, para2_j and returning on...

C++ Array Sort Me

Stuck on an array sorter. Have to sort numbers from largest to smallest. I'm trying two loops (one nested in the other). Here's the code: int counter=0; // inner counter int counter2=0; // outer counter int sparky[14]; //array set to 14 just to simplify things int holder; // holds the highest value int high; //stores the position where ...