framework/js/lib/helpers/punctuate.js
Toby Zerner bb04d91b08 Add helper function for punctuating a list
e.g. [1,2,3] ⇒ [1, ‘, ‘, 2, ‘, and’, 3]
2015-05-14 22:41:06 +09:30

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;
};