Best answer

List punctuation with line-item to text in Formatter

  • 5 April 2020
  • 3 replies
  • 55 views

Userlevel 1

Can anyone help me out with how to use Formatter to take a line-item list, turn it to text AND use appropriate list punctuation for a sentence.  Example

  1. apple
  2. pear
  3. plumb
  4. cherry

becomes “apple, pear, plumb and cherry” instead of “apple, pear, plumb, cherry”  ?

icon

Best answer by ikbelkirasan 6 April 2020, 02:28

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

Userlevel 7
Badge +12

Hi @thurfirhawat - Instead of the formatter, you could use a code step with the following code in it:

const fruits = inputData.fruits.split(",").map((fruit) => fruit.trim());
let text = "";
fruits.forEach((fruit, index) => {
if (index < fruits.length - 1) {
if (index < fruits.length - 2) {
text += `${fruit}, `;
} else {
text += `${fruit} and `;
}
} else {
text += fruit;
}
});

output = [
{
text
}
]

 

 

 

Userlevel 1

No.  The items are variable.  There might be 0 to ?. @AndrewJDavison_Luhhu 

Userlevel 7
Badge +10

Hi @thurfirhawat 

Question - will the list *always* have 4 items in it?