How to write array in .md file for hugo website - hugo

I'm stuck with hugo array syntax in md file.
I want to create a multidimensional array for site images that stores src and alt text.
With simple array I don't have problems
list: ["item-1", "item-2"]
But if I do something like this
list: [["scr": item-1", "alt": "alt-1"]["scr": item-2", "alt": "alt-2"]]
I have errors.
What is the right syntax for this?

The syntax seems to be consistent with the simple array.
list: [["scr": item-1", "alt": "alt-1"], ["scr": item-2", "alt": "alt-2"]]
You need commas between each array.

Related

Explode from a txt file

I use explode in my php code to load the strings from a txt file into an array. The strings are loaded into array with no problem, however, the first element has an index 0 but I want it to have an index 1. How do I achieve that?
I appreciate any help cause I've tried so many things and nothing seems to be working and I feel I got stuck.
You can use array_unshift to insert dummy element then remove it using unset as follows :
$ex_array = array("PHP","JAVA","C#","Python", "Javascript", "C");
array_unshift($ex_array,"");
unset($ex_array[0]);

Is there a way that I can write numpy arrays into a json file?

I want to store some settings for my plotting code in a json file, one of which is a long array of integers for the bins. Previously I generated this array with e.g.np.arange(0,550,50), however the json file obviously doesn't understand this:
{
"observables":[
{
"name": "pt",
"label": "p_T",
"ticks": np.arange(0,550,50),
"unit": "[GeV]"
}
]
}
Is there a way I can get away with writing the array in the json file in a shorthand way like I previously did with numpy, or am I going to have to write it longhand as a list, e.g. [0,50,100,150,200,250,...]?
I'm new to json files and so the only thing I can think of is writing it out longhand as a list, but I have a lot of observables to include and I might change this binning later, so this is not an ideal solution.

Trying to populate an array from a text file

I'm using xcode, swift 5.0.
I have a multidimensional array for a tableViewController to give a list with different sections.
I would like for the array to be taken from a text file which is stored remotely (so that the array contents can be updated without an app update).
Any advice on how to code for this?

How to use 2D array in selenium webdriver

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!!!

Filtering empty arrays from array of arrays in Scala

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)

Resources