Here is an implementation in the Scripting App:
// 🧲
const list = input.config().any_list
//console.log(list)
// 🧞♂️
function makeSentence(list) {
switch(list.length){
case 1:
//console.log(list[0])
output.set('sentence', list[0]);
break;
case 2:
let two = list
.join(' and ')
//console.log(two)
output.set('sentence', two);
break;
default :
let more = list.length ? list
.slice(0, list.length - 1)
.join(', ')
+ ', and ' + list.slice(-1)
: console.error('The list was totally empty!')
//console.log(more)
output.set('sentence', more)
}
}
// ▶
makeSentence(list)
// someday this will be the answer:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat
//
Let me know if that works for you as it is something that I am going to need very shortly in my own base. Thanks!