Is there an easier way than below to find the longest item in an array?
arr = [
[0,1,2],
[0,1,2,3],
[0,1,2,3,4],
[0,1,2,3]
]
longest_row = []
@rows.each { |row| longest_row = row if row.length > longest_row.length }
p longest_row # => [0,1,2,3,4]
Hi ,
I have silverlight app that post some data to another web application ,the data to post is converted to base 64 using code
byte[] byteArray = Encoding.UTF8.GetBytes(sDataToPost);
sDataToPost = Convert.ToBase64String(byteArray);
Another webapplication
get the data using the code
strText = System.Text.Encoding.ASCII.GetString(System.Convert.FromBase64String(postedData));
But it gives the exception invalid length for a base-64 char array
Thanks in Advance
DNM
I have a class like this
class someclass{
public function somemethod(){}
}
Now I have an array:
$somearray['someclass'] = new someclass();
$somearray['somemethod'] = 'somemethod';
How can I fire them, I tried the following:
$somearray['someclass']->$somearray['somemethod']();
usign this I get the following error:
Fatal error: Method name must be a string in ......................
Anyone have an idea on how to do this?
I need to create the following in my main method. Create an array of size 100 doubles. write a loop to sotr the number 150.0 - 249.0 in the 100 location.
public class Lab6_2 {
public static void main(String[] args)
{ double[] values;
values = new double [100];
double i = 0;
for(double i = 150.0; i<249.0;i++){
System.out.println(values[99]);
} } }
This may be a bit of an easy, headesk sort of question, but my first attempt surprisingly completely failed to work. I wanted to take an array of primitive longs and turn it into a list, which I attempted to do like this:
long[] input = someAPI.getSomeLongs();
List<Long> = Arrays.asList(input); //Total failure to even compile!
What's the right way to do this?
Is it possible to initialise an array in Java using the 'advanced' for loop?
e.g.
Integer[ ] numbers = new Integer[20];
int counter = 0;
for ( Integer i : numbers )
{
i = counter++;
}
for ( Integer i : numbers )
{
System.out.println(i);
}
This prints all nulls, why is that?
I 'm writing a code with JS and I don't know how to populate array when clicking on button. We have this code, which uses a list (ul), where the items (li) can be moved with mouse. How can do onclick to populate an array with 2 data, its first position and the last position?
<!doctype html>
<html lang="en">
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="https://raw.github.com/furf/jquery-ui-touch-punch/master/jquery.ui.touch-punch.min.js"></script>
<script>
$(function() {
$( ".documents" ).sortable();
$( ".documents" ).disableSelection();
});
</script>
<meta charset="utf-8">
<title>toArray demo</title>
<style>
span {
color: red;
}
</style>
</head>
<body>
Reversed - <span></span>
<ul id="opciones" class="documents">
<li>uno</li>
<li>dos</li>
<li>tres</li>
</ul>
<script>
function disp( li ) {
var a = [];
for ( var i = 0; i < li.length; i++ ) {
a.push( li[ i ].innerHTML );
}
$( "span" ).text( a.join( " " ) );
}
disp( $( "li" ).toArray() );
</script>
<input type="button" value="actualizar_array" onclick="disp('#opciones')" />
</body>
</html>
Very similar to this post
How can I declare template array as a parameter in templated function?
Something like this code:
template <unsigned i> void my_func (char (&a)[i]); //yes, I do need that reference
I have a string representing bits, such as:
"0000101000010000"
I want to convert it to get an array of bytes such as:
{0x0A, 0x10}
The number of bytes is variable but there will always be padding to form 8 bits per byte (so 1010 becomes 000010101).
I have a dynamic array of strings, the elements of which I would like to localize. Is there a way to localize the strings without iteration e.g. something like using "makeObjectsPerformSelector". Thank you
I need a big null array in C as a global. Is there any way to do this besides typing out
char ZEROARRAY[1024] = {0, 0, 0, /* ... 1021 more times... */ };
?
All, I want to create an object array foo[], where the constructor for Foo is
public Foo(string name, string discription){}
I have a database object which has a structure (not incuding stored procedures, functions or views for simplicity) like
public class Database
{
public string name { get; set; }
public string filename { get; set; }
public List<Table> tables { get; set; }
public Database(string name, string filename)
{
this.name = name;
this.filename = filename;
}
}
protected internal class Table
{
public string name { get; set; }
public List<Column> columns { get; set;}
public Table(string name, List<Column> columns)
{
this.name = name;
this.columns = columns;
}
}
protected internal class Column
{
public string name { get; set; }
public string type { get; set; }
public Column(string name, string type, int maxLength,
bool isNullable)
{
this.name = name;
this.type = type;
}
}
I would like to know the quickest way to add Column and Table information to the Foo[] object array?
Clearly I can do
List<Foo> fooList = new List<Foo>();
foreach (Table t in database.tables)
{
fooList.Add(new Foo(t.Name, "Some Description"));
foreach (Column c in t.columns)
fooList.Add(new Foo(c.Name, "Some Description"));
}
Foo[] fooArr = fooList.ToArray<Foo>();
But is there a quicker way? Clearly LINQ is likely to be slower for a query that does a simalar operation, but I care allot about speed here so any advice would be appreciated. Perhaps the use of a HashSet would be the way to go as there will not be duplicate entries...
Thanks for your time.
I am trying to fumble through python, and learn the best way to do things. I have a string where I am doing a compare with another string to see if there is a match:
if paid[j].find(d)>=0:
#BLAH BLAH
If 'd' were an array, what is the most efficient way to see if the string contained in paid[j] has a match to any value in 'd'?
I'm trying to create a WCHAR:
LONG bufferSize = foo.bar() + 1;
WCHAR wszBaz[bufferSize];
The compiler issues an error:
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2133: 'wszBaz' unknown size
What am I doing wrong?
UPDATE: I added const but it still gives the same error:
const LONG bufferSize = foo.bar() + 1;
WCHAR wszBaz[bufferSize];
How can I convert a Class to byte array in C#. This is a managed one so the following code is failing
int objsize = System.Runtime.InteropServices.Marshal.SizeOf(objTimeSeries3D);
byte[] arr = new byte[objsize];
IntPtr buff = System.Runtime.InteropServices.Marshal.AllocHGlobal(objsize);
System.Runtime.InteropServices.Marshal.StructureToPtr(objTimeSeries3D, buff, true);
System.Runtime.InteropServices.Marshal.Copy(buff, arr, 0, objsize);
System.Runtime.InteropServices.Marshal.FreeHGlobal(buff);
Thanks
I am new to jScript and have written this code [which works perfectly]. Its purpose is to test that the term for the amount of loan is not exceeded. Can the process be consolidated into one array where you pass the loan amount which returns the term based on the range i.e. 6000 to 7000 = 96
function TestMaxTerm()
{
var LnAmt = 14000 //Testing Purposes
var Term = 0 //Testing Purposes
if (LnAmt > 0 && LnAmt <= 1000){Term = 0;}
if (LnAmt > 1000 && LnAmt <= 2000){Term = 1;}
if (LnAmt > 2000 && LnAmt <= 3000){Term = 2;}
if (LnAmt > 3000 && LnAmt <= 4000){Term = 3;}
if (LnAmt > 4000 && LnAmt <= 5000){Term = 4;}
if (LnAmt > 5000 && LnAmt <= 6000){Term = 5;}
if (LnAmt > 6000 && LnAmt <= 7000){Term = 6;}
if (LnAmt > 7000 && LnAmt <= 8000){Term = 7;}
if (LnAmt > 8000 && LnAmt <= 9000){Term = 8;}
if (LnAmt > 9000 && LnAmt <= 10000){Term = 9;}
if (LnAmt > 10000 && LnAmt <= 11000){Term = 10;}
if (LnAmt > 11000 && LnAmt <= 12000){Term = 11;}
if (LnAmt > 11000){Term = 12;}
//Obtain Maximum Term for Loan Amount
var MaxTerm = new Array();
MaxTerm[0] = 24; MaxTerm[1]=36; MaxTerm[2] = 48; MaxTerm[3] = 60;
MaxTerm[5] = 72; MaxTerm[5]=84; MaxTerm[6] = 96; MaxTerm[7] = 108;
MaxTerm[8] = 120; MaxTerm[9]=132; MaxTerm[10] = 164; MaxTerm[11] = 176;
MaxTerm[12] = 420;
var text = MaxTerm[Term];
alert(text);
}
I've got code that takes a PIL image and converts it to a ctypes array to pass out to a C function:
w_px, h_px = img.size
pixels = struct.unpack('%dI'%(w_px*h_px), img.convert('RGBA').tostring())
pixels_array = (ctypes.c_int * len(pixels))(*pixels)
But I'm dealing with big images, and unpacking that many items into function arguments seems to be noticeably slow. What's the simplest thing I can do to get a reasonable speedup?
I'm only converting to a tuple as an intermediate step, so if it's unnecessary, all the better.
If I have an array named $myArray how can I get a reference to it from a string of the same name myArray. I tried:
eval('myArray');
But that gave me an error.
I am having difficulty for using array model binding.
Actually I can see that the values sent from the views are not binded to the model and the arrays still have the values already instantiated. How can I solve this problem?
hi friends,
How to read XML file into two dimensional array using java. Am new to this concept. Please suggest me any ideas and suggest any websites and examples regarding this question.
Hi folks.
I have a array like this:
my @arr = ("Field3","Field1","Field2","Field5","Field4");
Now i use map like below , where /DOSOMETHING/ is the answer am seeking.
my %hash = map {$_ => **/DOSOMETHING/** } @arr
Now I require the hash to look like below:
Field3 = 0
Field1 = 1
Field2 = 2
Field5 = 3
Field4 = 4
Any help?