arrays

Looping through array and totalling values

Hello, I require a bit of assistance, if someone would be kind enough to help. I have an array with values, which I want to loop through, and if any of the 'user_id values' are the same then to total the 'max_score' value of the duplicate user id's. Array ( [0] => Array ( [user_id] => 2 [max_score]...

java array thread safety

ArrayList in java is thread safe.and it is implemented using array. So, is the access to arrays in java thread safe??does the access to arrays needs to be synchronized?? ...

Why doesn't the Array Equality Function Work as Expected?

In Programming in Scala the authors write that Scala's == function compares value equality instead of reference equality. This works as expected on lists: scala> List(1,2) == List(1,2) res0: Boolean = true It doesn't however work on arrays: scala> Array(1,2) == Array(1,2) res1: Boolean = false In Programming Scala the authors reco...

Java unmodifiable array

final Integer[] arr={1,2,3}; arr[0]=3; System.out.println(Arrays.toString(arr)); I tried the above code to see whether a final array's variables can be reassigned[ans:it can be].I understand that by a final Integer[] array it means we cannot assign another instance of Integer[] apart from the one we have assigned initially.I would like...

Initializing attributes in Ruby objects

I create a new object of type Spam, with attr_accessor to both hooray and name and I have the initialize method. I'm expecting when I create a new object the object is loaded with a var of name with "Whammy" and a empty array named hooray. Though I'm not getting this behavior. Can anyone explain, thank you in advance. module Test class ...

converting String.data() into an array

Hi, I want to take a string,and populate an array with its values. I know the length of the string is 16. I have tried char *bit_number[16]; bit_number = bin.data(); and char bit_number[16]; bit_number = bin.data(); I don't understand what String.data() is returning, why can't I assign it directly to an array? I'm getting compiler ...

Create dynamic associated array. Please help!

Hello, I got a database with 2 fields (amount and name). I want to get all data from the database (40 rows) and create an associated array out of it like this. $arr = array("amount" => "12", "name" => "John"); How is this done dynamically in PHP? I am stuck. ...

how to get attribute value as array using jQuery

I save an array value as attribute of element, but I can't get the attribute value as an array, it's string. How can I get it as an array? I will add code for this question. Thanks. Code: <table columnArray="">.....</table> var columns = $('table > thead > tr > *').map(function(){return {left: $(this).position().left, width: $(this)...

Maximum values for array sizes in C

Hello. Just a quick question: What are people's practices when you have to define the (arbitrary) maximum that some array can take in C. So, some people just choose a round number hoping it will be big enough, others the prime number closer to the round number (!), etc., other some more esoteric number, like the prime number closer to......

How to restore an array with NSCoder

So far I have the following: - (id)initWithCoder:(NSCoder*) coder { self = [super initWithCoder: coder]; if (self) { // Call a setup method } return self; } Am I supposed to put the code to load the array in here? What could should I put and where should I put it? ...

When does initWithCoder get called?

This will load an array - (id)initWithCoder:(NSCoder*) coder { self = [super initWithCoder: coder]; if (self) { myArray=[coder decodeObjectForKey:@"myArray"]; } return self; } What is the code that will call this function so that the array can be loaded? ...

Tutorial for saving an array of custom objects

Is there a tutorial for saving and restoring an array of custom objects? ...

Printing specific items in an array

I'm a newbie and trying to do this for my college class. I have created an array called birds: Here is my code: <?php // This script creates an array called birds and then prints out the birds 1-3 and then prints the birds 0,, 2 and 4 $birds = array ("Whip-poor-will|Chickadee|Pileated Woodpecker|Blue Jay|Rufus-sided Towhee|Scarlet Tanag...

PHP array combinations

Hello, I have an array of 7 numbers (1,2,3,4,5,6,7) and I want to make pairs of 5 numbers like (1,2,3,4,5),(1,2,3,4,6,),(1,2,3,4,7) . (1,2,3,4,5) is equal to (4,5,3,1,2) I would like to know if there is a function in PHP or any algorithm that can do this ? I have no idea where to start from. Can you help me ? I want all the combination...

Posting an array in php(smarty)

Hey, I'm trying to post multiple answers(using checkboxes) in a form. The question is pick what months your available, here is my code... $smarty->assign('month', array( '1' => 'January', '2' => 'February', '3' => 'March', '4' => 'April', '5' => 'May', '6' => 'June', '7' => 'July', '8' => 'August', '9' => 'September', '10'...

Finding the product of a variable number of string arrays in Java

Is there a Java equivalent to Ruby's Array#product method, or a way of doing this: groups = [ %w[hello goodbye], %w[world everyone], %w[here there] ] combinations = groups.first.product(*groups.drop(1)) p combinations # [ # ["hello", "world", "here"], # ["hello", "world", "there"], # ["hello", "everyone", "here"], # ["he...

C Programming - Malloc Structs and undefined arrays

I am writing a program in C and I am trying to create these structs. I have three of them: the first consisting of 2 ints and 2 chars, the second consisting of an int and an undefined array of pointers to the first one, and a third which contains 4 longs and 2 ints along with an undefined array of pointers to the second. I am having ...

selecting hash values by value property in ruby

In Ruby, I have a hash of objects. Each object has a type and a value. I am trying to design an efficient function that can get the average of the values of all of objects of a certain type within the hash. Here is an example of how this is currently implemented: #the hash is composed of a number of objects of class Robot (example name...

C: Passing an array into a function 'on the fly'

I have a function, and I want to pass an array of char* to it, but I don't want to create a variable just for doing that, like this: char *bar[]={"aa","bb","cc"}; foobar=foo(bar); To get around that, I tried this: foobar=foo({"aa","bb","cc"}); But it doesn't work. I also tried this: foobar=foo("aa\0bb\0cc"); It compiles with a w...

Array splice throws error in IE

IE7 and IE8 are not letting me splice my array (Safari, Chrome, Firefox work): lzaCreateAd1.weatherArray = new Array(); var jWeatherIcon = $('.weatherIcon'); jWeatherIcon.bind('click', function (){ var targetID = $(this).attr('id') + 'Box', idVal = targetID.substr(5,1); var j...