Add helper function for punctuating a list

e.g. [1,2,3] ⇒ [1, ‘, ‘, 2, ‘, and’, 3]
This commit is contained in:
Toby Zerner 2015-05-14 22:31:24 +09:30
parent a8ad5a1ac8
commit 8156f23968

View File

@ -0,0 +1,13 @@
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;
};