mirror of
https://github.com/flarum/framework.git
synced 2024-12-01 14:20:47 +08:00
bb04d91b08
e.g. [1,2,3] ⇒ [1, ‘, ‘, 2, ‘, and’, 3]
14 lines
283 B
JavaScript
14 lines
283 B
JavaScript
export default function punctuate(items) {
|
|
var newItems = [];
|
|
|
|
items.forEach((item, i) => {
|
|
newItems.push(item);
|
|
|
|
if (i <= items.length - 2) {
|
|
newItems.push((items.length > 2 ? ', ' : '')+(i === items.length - 2 ? ' and ' : ''));
|
|
}
|
|
});
|
|
|
|
return newItems;
|
|
};
|