How to iterate a list & counter ++ in a loop in Sightly(HTL) - sightly

how to achieve this condition in sightly HTL.
I tried but I couldn't able to implement this condition.
Pls help me

You can use itemList.odd and itemList.even with data-sly-test to conditionally render the divs. See https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#226-list!

Related

Google Sheets' operators

Do Google Sheets have a || operator like most of the languages?
I'm trying to use it inside a switch function to nest some values.
=SWITCH(G5;"BLACKOLIVES";"BLACK";"JABOTICABA";"BLACK";"MULLBERIES";"BLACK")
this is how I'm doing it now, I want to do it somewhat like whats next
=SWITCH(G5;"BLACKOLIVES"||"JABOTICABA"||"MULLBERIES";"BLACK")
but this statement returns an error and I can't find a ||-like operator in the documentation.
Does anyone have an idea how to solve this?
Maybe you could use something like
=if(regexmatch(G5, "BLACKOLIVES|JABOTICABA|MULLBERIES"),"BLACK",)
In regular expressions the "pipe"-character means 'or'...
an alternative syntax would be:
=IF(OR(G5="BLACKOLIVES", G5="JABOTICABA", G5="MULLBERIES"), "BLACK", )

Java 8- forEach method iterator behaviour

I recently started checking new Java 8 features.
I've come across this forEach iterator-which iterates over the Collection.
Let's take I've one ArrayList of type <Integer> having values= {1,2,3,4,5}
list.forEach(i -> System.out.println(i));
This statement iteates over a list and prints the values inside it.
I'd like to know How am I going to specify that I want it to iterate over some specific values only.
Like, I want it to start from 2nd value and iterate it till 2nd last value. or something like that- or on alternate elements.
How am I going to do that?
To iterate on a section of the original list, use the subList method:
list.subList(1, list.length()-1)
.stream() // This line is optional since List already has a foreach method taking a Consumer as parameter
.forEach(...);
This is the concept of streams. After one operation, the results of that operation become the input for the next.
So for your specific example, you can follow #Joni's command. But if you're asking in general, then you can create a filter to only get the values you want to loop over.
For example, if you only wanted to print the even numbers, you could create a filter on the streams before you forEached them. Like this:
List<Integer> intList = Arrays.asList(1,2,3,4,5);
intList.stream()
.filter(e -> (e & 1) == 0)
.forEach(System.out::println);
You can similarly pick out the stuff you want to loop over before reaching your terminal operation (in your case the forEach) on the stream. I suggest you read this stream tutorial to get a better idea of how they work: http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/

Using dustjs how do I show a block of code when an array's size is greater than one

I am using dust 1.1.1. I've tried nesting the #size help inside of an #if but that broke.
Another trick to it is once I've determined the length is greater than one I then want to iterate through the array.
The Dust grammar does not allow a helper to be used inside another helper, except in the body.
Instead, I would try something like this:
{#myArray}
{#gt key=$len value=1}{.}{/gt}
{/myArray}
This will only output the value of the element in the array if the length of the array ($len) is greater than 1.
My workaround for this was:
{?myArray[1]}
{!Do greater than one stuff!}
{/myArray[1]}

Watir/Ruby - Loop through a search results list - search for element ,if element found - action and exit loop

I currently have a list of search results that I want to loop though and find a particular element. This element can occur multiple times(from a few to thousands) but I just want to find the first instance of the element,click it and then exit my loop.
Tried the following but think i am a bit off
i = 0
#browser.div(:id=>"resultsList").lis.each do|li| -- loop through list
#browser.link(:href=>"linkname").exists --- check if element exists
#browser.goto(#browser.link(:href=>"linkname") --if it exists click
break if i == 1 ---then break out of loop
end
Any pointers would be appreciated
Thanks!
You do not need to loop through the elements. By default, Watir-Webdriver will return the first matching element.
Just do:
#browser.div(:id=>"resultsList").link(:href=>"linkname").click
This will click the first link in the search results that has the href of "linkname". Note if you actually want the link text (not href) to match "linkname" it should be link(:text=>"linkname").

Google Spreadsheet long IF statement?

I have this statement:
=if(
F1B!D3="1",50+FLOOR(D2/10,1),
if(F1B!D3="2",40),
if(F1B!D3="3",30),
if(F1B!D3="4",25),
if(F1B!D3="5",20),
if(F1B!D3="6",19),
if(F1B!D3="7",18),
if(F1B!D3="8",17),
if(F1B!D3="9",16),
if(F1B!D3="10",15),
if(F1B!D3="11",14),
if(F1B!D3="12",13),
if(F1B!D3="13",12),
if(F1B!D3="14",11),
if(F1B!D3="15",10),
if(F1B!D3="16",9),
if(F1B!D3="17",8),
if(F1B!D3="18",7),
if(F1B!D3="19",6),
if(F1B!D3="20",5),
if(F1B!D3="21",4),
if(F1B!D3="22",3),
if(F1B!D3="23",2),
if(F1B!D3="24",1));
But GoogleDocs return me "error: Wrong number of arguments to IF"
What I'am doing wrong?
You can't pass infinitely many arguments to IF. There's a single condition, a single "THEN", and a single "ELSE". You need to "nest" your IF statements, where each new IF() in part of the previous IF statement's ELSE. Something like this (abbreviated):
=if(
F1B!D3="1",50+FLOOR(D2/10,1),
if(F1B!D3="2",40,
if(F1B!D3="3",30,
if(F1B!D3="4",25,
if(F1B!D3="5",20,
if(F1B!D3="6",19,
if(F1B!D3="7",18)))))))
Trying to apply too many IFs, far more than necessary:
=IF(F1B!D3=1,50+FLOOR(F1B!D2/10,1),iferror(CHOOSE(F1B!D3-1,40,30,25),25-F1B!D3))
Also do not append ;.

Resources