You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Desired behavior
To have a filter function that takes an array of words, i.e. ['apples', 'oranges', 'lemons'] and spits out apples, oranges and lemons. If it receives an array of length 2 it will spit out apples and oranges.
Yes I know the solution to this is easy but I always forget how slice works.
Todo
The solution is array.slice(0, -1).join(', ') + ' and ' + array.slice(-1) so just need to add this to a function. Maybe worth adding to journalize?
The text was updated successfully, but these errors were encountered:
mandicai
changed the title
Make a utility for taking an array of words and joining them in a copy-edit friendly way
Make a utility that takes an array of words and joins them in a copy-edit friendly way
May 12, 2020
(we already have something like this in the template to process multiple authors:
By {%- for author in context.authors or ['Super Cool Corgi', 'Friends'] -%}
{% if not loop.last %}{{ authorComma() }}{% elif not loop.first %} and{% endif %} {{ author }}
{%- endfor -%}
mandicai
changed the title
Make a utility that takes an array of words and joins them in a copy-edit friendly way
Running list of utilities to include in the kit
Jun 4, 2021
Desired behavior
To have a filter function that takes an array of words, i.e.
['apples', 'oranges', 'lemons']
and spits outapples, oranges and lemons
. If it receives an array of length 2 it will spit outapples and oranges
.Yes I know the solution to this is easy but I always forget how slice works.
Todo
The solution is
array.slice(0, -1).join(', ') + ' and ' + array.slice(-1)
so just need to add this to a function. Maybe worth adding tojournalize
?The text was updated successfully, but these errors were encountered: