Hi i want to use 2D array in my code.
I am using that in loop to point element to each other.
I am trying 2D arrays,
a[i]=b[j]
in array a[i] i am going to store some xpath and in another array b[j] i want to store their values.i am using ruby plus selenium.
Instead of using 2D array, you can use "Hash" for better programming.
This is the sample example of my code :
some_hash_name = { "xpath 1" => "value 1","xpath 2" => "value 2" }
some_hash_name.each do |path,value|
some_hash_name.select_by(:text, "#{path}")
$driver.find_element(:xpath,"//tbody/tr[3]/select/option[#{value}]").click
In this way you can use "hash" in Ruby.
Hope this will help you.
Cheers!!!
Related
When using the MATLAB jsonencode function it seems very difficult to convert size 1 arrays into the correct JSON format i.e. [value]. For example if I do:
jsonencode(struct('words', [string('hello'), string('bye')]))
Then this produces:
{"words":["hello","bye"]}
which is correct. If however I do:
jsonencode(struct('words', [string('hello')]))
Then it produces:
{"words":"hello"}
losing the square brackets, which it needs because it is in general an array. The same happens when using a cell rather than an array, although using a cell does work if it's not inside a struct.
Any idea how I can work around this issue?
It seems this can be solved by using a cell rather than an array and then not creating the struct inline. Like
s.words = {'hello'};
jsonencode(s)
Output:
{"words":["hello"]}
I presume when created inline the cell functionality of matlab is actually trying to make multiple structs rather than multiple strings. Note that this still won't work with arrays as matlab treats a size one array as a scalar.
I am trying to use an array in NetLogo to store my images and call the values using their index. Looks like I am getting stuck with common manner of accessing the array's value via arrayName[0].
How do I do that in NetLogo? googling doesn't seem to have the answer.
My array:
let imgArray ["easy1.png" "easy2.png" "easy3.png" "easy4.png" "easy5.png"]
I am trying to fix the image in the following manner:
clear-drawing import-drawing imgArray[1]
You're looking for item:
item 1 imgArray
Note that it's zero-indexed, so the first item is item 0 imgArray, though first imgArray is more idiomatic.
Also, arrays in NetLogo are called lists.
I can append to a single array using
{append var='name' value='Bob' index='first'}
However, if I have a multi-dimensional array such as:
$name[first][last] = ['this','array']
and I want to append another value to the array at $name[first][last] e.g. to make the array like this:
$name[first][last] = ['this','array','appended']
how can I do this in the smarty template?
You can do this without using append:
{$name[first][last][] = 'this'}
{$name[first][last][] = 'array'}
{$name[first][last][] = 'appended'}
I must highlight though - templates should be used for specific purpose: to display prepared data; having to do the above is a code smell
I've tested many cases to try achieve it and I think it's not possible (in documentation there is also no info or example of multidimensional key or var)
You should also really think do you need it at all. Logic should be in PHP and role of Smarty is only displaying data not manipulating them
I have an array of arrays of type String, which looks something like:
[[""],["lorem ipsum", "foo", "bar"], [""], ["foo"]]
What I'd like to do is filter out all of the elements in the array that are themselves an empty array (where in this instance, by "empty array", I mean arrays that contain just an empty string), to leave me just with:
[["lorem ipsum", "foo", "bar"], ["foo"]]
However I'm struggling to find a way to do this (still new to Scala) - any help much appreciated!
Thanks.
Edit (with Rogach's simplification):
array.filterNot(_.forall(_.isEmpty))
In your description you ask how to
filter out all of the elements in the array that ... contain just an
empty string.
The currently accepted answer does this, but also filters out empty arrays, and arrays containing multiple empty strings (i.e. not just [""], but [] and ["", "", ""] etc. as well. (In fact, the first part x.isEmpty || is completely redundant.) Translating your requirement literally, if your array is xss, you need
xss.filter(_ != Array("")) // does not work!
This doesn't work because the equals method for Java arrays doesn't work as you might expect. Instead, when comparing Arrays, use either sameElements or deep:
xss.filterNot(_ sameElements Seq(""))
xss.filter(_.deep != Seq(""))
In idomatic Scala code you don't use Array much, so this doesn't crop up too often. Prefer Vector or List.
In your case, you could use:
array.filterNot(_.corresponds(Array("")){_ == _})
Use the following:
val a = Array(Array(), Array(), Array(3,1,2016), Array(1,2,3026))
a.filter(_.length>0)
Is there a way to make an array composed of "tags", so I can refer to them by their "name"?
So usually when I want to refer to a position in my array I would do something like:
MyArray:Array = new Array( ["Marco", 26, "Portugal" ] );
trace(MyArray[2]);
Output: "Portugal"
I want to use an array where the positions have diferent names. So I wanted to be something like:
MyArray:Array = new Array( ["Marco", 26, "Portugal" ] );
trace(MyArray[Country]);
Output: "Portugal"
I'm pretty sure "tag" or "name" of the array isnt the propper term to use, but I don't know the correct one, so excuse me on that. Its also probably a easy question, but something that I never needed to use untill now. I'm building a "Area" array with positions, heigths and widths of several movieclips on stage, so I could use some simplification of the array to avoid always using numbers.
Thank you.
You can just use the Object class, it is the simplest way to use associative arrays in as3:
var ob:Object = {
name: "Marco",
age: 26,
country:"Portugal"
};
trace(ob.country);
//output: Portugal
I recommend you to check this article on Adobe's website for further info: ActionScript 3 fundamentals: Associative arrays, maps, and dictionaries
While, I see you are using Array, it's no way to give a name for every element.
I suggest you the "Map" data struct in AS3。
var DC:Dictionary=new Dictionary;
DC["Country"] = "Portugal";
DC["name"] = "Marco";
...
Hope this will help you.