I'm trying to find the first and second half of a string of numbers with ruby ignoring the central digit if the length is odd
i.e
input = "102"
first_half = "1"
second_half = "2"
using this code
i = gets
first_half=i[0..(i.length / 2 - 1).floor]
second_half = i[i.length -first_half.length)..i.length - 1]
print "#{first_half}\n#{second...
If I have an object with an array as an attribute, what is the easiest way to access it?
$obj->odp = array("ftw", "pwn", array("cool" => 1337));
//access "ftw"
$obj->odp->0
//access 1337
$obj->odp->2->cool
This doesn't seem to work. Is there something I'm doing wrong, or do I have to first assign it to a variable?
$arr = $obj->odp;...
I found this code snippet on a different post that I don't quite understand and would appriciate someone explaining.
private bool[] GetPageNumbersToLink(IPagedResult result)
{
if (result.TotalPages <= 9)
return new bool[result.TotalPages + 1].Select(b => true).ToArray();
...
http://stackoverflow.com/questions/136836/c-arr...
How can you combine the two arrays?
They are simplified as follows which is enough for this question. This question is based on this answer.
1
[a][b][]
and
2
[a][c]
where both arrays has one common subarray [a].
I would like to have this
[a][c][b][]
I have run the following command unsuccessfully
array1[a] + array2[a]
...
I'm trying to apply a class to a link only if the current page equals that link.
I find the current page with:
var pathname = window.location.pathname.split("/")[window.location.pathname.split("/").length - 1];
This grabs the url of the page and saves whatever is after the last /, which in the case of my page is 'index.html'.
Now, ...
I know this is probably a simple question, but I'm attempting a tweak in a plugin & js is not my expertise and I got stumped on how to do the following:
I have an array that can contain a number of values ($fruit) depending on what a user has entered. I want to add another variable to the array that isn't determined by manual input.
I...
Given an array:
$a = array(
'abc',
123,
'k1'=>'v1',
'k2'=>'v2',
78,
'tt',
'k3'=>'v3'
);
With its internal pointer on one of its elements, how do I insert an element after the current element?
And how do I insert an element after a key-known element, say 'k1'?
Performance Care~
...
I have two sequential (non-associative) arrays whose values I want to combine into a new array, ignoring the index but preserving the order. Is there a better solution (i.e. an existing operator or function) other than do the following:
$a = array('one', 'two');
$b = array('three', 'four', 'five');
foreach($b as $value) {
$a[] = $v...
Duplicate of What is the purpose/advantage of using yield return iterators in C#?
Okay it just not this. Can you explain me in details that how does the two different?
Like Returning an Array (Lets say string)
or doing a yield return with iterator(also string)
I find them to be the same.
Please go into detail.
...
When should I use an ArrayList in Java, and when should I use an array?
...
Hello,
I am creating a series of arrays from template tags in a content management system, and outputting the titles of these arrays as arrays labeled with variables:
<Loop>
$<GeneratedArrayName1> = array( "foo" => "bar" );
$<GeneratedArrayName2> = array( "foo" => "bar" );
</Loop>
I'm also generating another array of possible Gen...
Hi I have this code
-(void)setUserFilters{
//init the user filters array
userFilters = [[NSMutableArray alloc] init];
SearchCriteria *tmpSc= [[SearchCriteria alloc] init];
for(int i=0;i<[searchFilters count];i++)
{
tmpSc=[self.searchFilters objectAtIndex:i];
if(tmpSc.enabled==TRUE)
[userFilters addObject:tmpSc]...
Hi,
I need to create an array of object literals like this:
var myColumnDefs = [
{key:"label", sortable:true, resizeable:true},
{key:"notes", sortable:true,resizeable:true},......
In a loop like this:
for ( var i=0 ; i < oFullResponse.results.length; i++) {
console.log(oFullResponse.results[i].label);
}
The value of '...
This failed:
define('DEFAULT_ROLES', array('guy', 'development team'));
Apparently, constants can't hold arrays. What is the best way to get around this?
define('DEFAULT_ROLES', 'guy|development team');
//...
$default = split(DEFAULT_ROLES, '|');
This seems like unnecessary effort.
...
Hello all,
I have this:
foreach ($country as $value){
The contents of $country using print_r is this:
Array
However, when I print_r all of POST variables it shows me country as single array rather than an array within an array as the above suggests?
Array (
[entry] => http://www.google.com
[SelectLocation] => Canada
...
The questions says it all:
...
int ndigit[10];
...//fill in the array with 0s
while((c = getchar()) != EOF)
if(c >= '0' && c <= '9')
++ndigit[c - '0']; //<== unable to understand this part
supposedly, the array stores incoming digit chars from the input stream...
...
Hi, I'm trying to make an object in one array equal to another. If I set each property individually, it works fine, but I want to set one object equal to antoher without writing a function to run through each property.
-(void)DrawCard: (int) wp{
[self GetNc :(wp)];
if (nc > 0){
((card*) [[Hands objectAtIndex:wp] objectAtIndex:nc]) = (...
I have the following class:
private class Info{
public String A;
public int B;
Info(){};
public OtherMethod(){};
private PrivMethod(){};
}
And I want to create an array of this class, but I want to provide a two dimensional array as an argument to the constructor, ie:
Info[] I = new Info({{"StringA", 1}, {"Strin...
If I know the length of an array, how do I print each of its values in a loop?
...
Hi all I have an array like this
public var dataAL:Array=[
{Kiv:"cash", jan:26,janTarget:28,feb:27,febTarget:26,mar:30,marTarget:32,apr:31,aprTarget:32,may:28,mayTarget:29,jun:46,junTarget:32,jul:37,julTarget:39,aug:40,augTarget:42,sep:41,sepTarget:42,oct:48,octTarget:49,nov:40,novTarget:41,dec:38,decTarget:40},
...