ruby - Make array elements lowercase with Liquid filters for sorting -
i can't figure out how case-insesitively sort array containing strings: ["a", "c", "e", "b", "d"]
["a", "b", "c", "d", "e"]
.
{% assign input = "a,c,e,b,d" | split:"," %} {{ input | join: "-" }} {{ input | map: 'downcase' | join: "-" }} {{ input | map: 'downcase' | sort | join: "-" }} {{ input | map: 'length' | join: "-" }} {{ input | map: 'size' | join: "-" }}
what missing map:
?
expected output:
a-c-e-b-d a-c-e-b-d a-b-c-d-e 1-1-1-1-1 1-1-1-1-1
actual output:
a-c-e-b-d ---- ---- ---- ----
note: @ first tried map: downcase
(without quotes), got no implicit conversion nil integer.
ok, hack, if knows better please post answer.
{% assign input = "a,c,e,b,d" | split:"," %} {% capture intermediate %}{% entry in input %}{{ entry | downcase }}{{ entry }}{% unless forloop.last %}{% endunless %}{% endfor %}{% endcapture %} {% assign intermediate_sorted = intermediate | split:'' | sort %} {% capture sorted %}{% entry in intermediate_sorted %}{{ entry | split: '' | last }}{% unless forloop.last %}{% endunless %}{% endfor %}{% endcapture %} {% assign sorted = sorted | split: '' %} {{ sorted | join: "-" }}
will output a-b-c-d-e
.
the us (unit separator, \u001f, not \u241f) , rs (record separator, \u001e, not \u241e) 2 characters unlikely appear in input, can used safely of time. ,
, |
if want sort css ids example.
Comments
Post a Comment