I am trying to figure out how can i distribute particular elements of a list, based on an if statement.
This is the list:
@x = ["american", "assistive", "audio", "blind", "braille", "closed-captioning", "closed-captioning", "deaf", "low", "phone", "question-circle", "question-circle", "sign", "tty", "universal", "wheelchair"]
This is my haml code:
%ul.list-inline
- @x.each do |i|
- if i[0].length < i[1].length
%li
%i{:class=>"fas fa-#{i[0]} fa-2x"}
%span.f6 #{i[0]}
- else
%li
%i{:class=>"far fa-#{i[1]} fa-2x"}
%span.f6 #{i[1]}
What i am trying to do, is to determine the length of each string in the list and compare it to the length of the next string in the list.
Once the second string is determined as being a duplicate, it should go under the else statement.
The problem i am facing, is that by going with i[0], instead of the first string in the list, i am getting the first letter of the each string in the list.
I don't know if my way of using length is the best way to solve this issue, so if anyone else has a better solution i am open for it, as long as it gets the job done.
I am thinking that maybe if i could filter the elements in the list based on which elements are unique and which are duplicates, i could then distribute them accordingly.
But how i do that?
Thank you.
Aucun commentaire:
Enregistrer un commentaire