arrays

Comparing Arrays of Objects in JavaScript

I want to compare 2 arrays of objects in JavaScript code. The objects have 8 total properties, but each object will not have a value for each, and the arrays are never going to be any larger than 8 items each, so maybe the brute force method of traversing each and then looking at the values of the 8 properties is the easiest way to do w...

Ruby - Convert Integer to String

In Ruby, trying to print out the individual elements of a String is giving me trouble. Instead of seeing each character, I'm seeing their ASCII values instead: >> a = "0123" => "0123" >> a[0] => 48 I've looked online but can't find any way to get the original "0" back out of it. I'm a little new to Ruby to I know it has to be somethi...

Pass reference to element in C# Array

I build up an array of strings with string[] parts = string.spilt(" "); And get an array with X parts in it, I would like to get a copy of the array of strings starting at element parts[x-2] Other than the obvious brute force approach (make a new array and insert strings), is there a more elegant way to do this in C#? ...

How to declare an array of strings in C++?

I am trying to iterate over all the elements of a static array of strings in the best possible way. I want to be able to declare it on one line and easily add/remove elements from it without having to keep track of the number. Sounds really simple, doesn't it? Possible non-solutions: vector<string> v; v.push_back("abc"); b.push_back("x...

[c#] How to pass a single object[] to a params object[]

I have a method which takes params object[] such as: void Foo(params object[] items) { Console.WriteLine(items[0]); } When I pass two object arrays to this method, it works fine: Foo(new object[]{ (object)"1", (object)"2" }, new object[]{ (object)"3", (object)"4" } ); // Output: System.Object[] But when I pass a single object[]...

How do I convert a Ruby string with brackets to an array?

I would like to convert the following string into an array/nested array: str = "[[this, is],[a, nested],[array]]" newarray = # this is what I need help with! newarray.inspect # => [['this','is'],['a','nested'],['array']] ...

What is the best way to convert an array to a hash in Ruby

In Ruby, given an array in one of the following forms... [apple, 1, banana, 2] [[apple, 1], [banana, 2]] ...what is the best way to convert this into a hash in the form of... {apple => 1, banana => 2} ...

Best way to sort an array in delphi

Say I have an array of records which I want to sort based on one of the fields in the record. What's the best way to achieve this? TExample = record SortOrder : integer; SomethingElse : string; end; var SomeVar : array of TExample; ...

PHP, Arrays, and References

Why does the following code not work as I was expecting? <?php $data = array( array('Area1', null, null), array(null, 'Section1', null), array(null, null, 'Location1'), array('Area2', null, null), array(null, 'Section2', null), array(null, null, 'Location2') ); $root = array(); foreach ($data as $row) { if ($...

Order an Array like another Array in C#

I'm looking for the best algorithm to take array A {0,1,2,3} and make order it like array B {3,1,0,2}. Any ideas? ...

Javascript collection of DOM objects - why can't I reverse items order with Array.reverse()?

What would be the problem with reversing the array of DOM objects got from a command like: var imagesArr = new Array(); imagesArr = document.getElementById("myDivHolderId").getElementsByTagName("img"); imagesArr.reverse(); When i call the reverse() method, the script stops executing with the error 'imagesArr.reverse is not a function'...

What is the most efficient way to sort an Html Select's Options by value, while preserving the currently selected item?

I have jQuery but I'm not sure if it has any built-in sorting helpers. I could make a 2d array of each item's text, value, and selected properties, but I don't think that javascript's built in Array.sort() would work correctly. ...

Can parallel traversals be done in MATLAB just as in Python?

Using the zip function, Python allows for loops to traverse multiple sequences in parallel. for (x,y) in zip(List1, List2): Does MATLAB have an equivalent syntax? If not, what is the best way to iterate over two parallel arrays at the same time using MATLAB? ...

How to iterate a jagged array?

This has been driving me crazy for a few days. Why doesn't the following work? Dim arr(3, 3) As Integer For y As Integer = 0 To arr.GetLength(0) - 1 For x As Integer = 0 To arr.GetLength(y) - 1 arr(y, x) = y + x Next Next Also, what if the array looked like this instead? { {1, 2, 3}, {4, ...

How to get hashes out of arrays in Perl?

I want to write a little "DBQuery" function in perl so I can have one-liners which send an SQL statement and receive back and an array of hashes, i.e. a recordset. However, I'm running into an issue with Perl syntax (and probably some odd pointer/reference issue) which is preventing me from packing out the information from the hash that ...

haXe and arrays Dynamic type

Hi, I know it's unlikely but maybe there is someone who knows haXe language. I have a variable of Dynamic type and I know for sure one of it's fields, lets call it an 'a' actually is an array. But when I'm writing var d : Dynamic = getDynamic(); for (t in d.a) { } I get a compilation error on line two, saying 'You can't iterate on a ...

How to check if element in groovy array/hash/collection/list?

How do I figure out if an array contains an element? I thought there might be something like [1,2,3].includes(1) which would evaluate as 'true' ...

How to deal with arrays (declared on the stack) in C++?

I have a class to parse a matrix that keeps the result in an array member: class Parser { ... double matrix_[4][4]; }; The user of this class needs to call an API function (as in, a function I have no control over, so I can't just change its interface to make things work more easily) that looks like this: void api_func(const doub...

Casting between multi- and single-dimentional arrays

This came up from this answer to a previous question of mine. Is it guaranteed for the compiler to treat array[4][4] the same as array[16]? For instance, would either of the below calls to api_func() be safe? void api_func(const double matrix[4][4]); // ... { typedef double Matrix[4][4]; double* array1 = new double[16]; double ...

.Net arrays with lower bound > 0

Although perhaps a bizare thing to want to do, I need to create an Array in .Net with a lower bound > 0. This at first seems to be possible, using: Array.CreateInstance(typeof(Object), new int[] {2}, new int[] {9}); Produces the desired results (an array of objects with a lower bound set to 9). However the created array instance can n...