The object Listhas a method mkStringthat can convert to a delimited string. However, most human languages consider the last element when listing a list. For example, A, B, C, and D.
What is the best in terms of code size and reasonable efficiency for this? To be precise, I am looking for a function that satisfies:
assertEquals("",foo(List()))
assertEquals("A",foo(List("A")))
assertEquals("A and B",foo("List("A","B")))
assertEquals("A, B and C", foo(List("A","B","C")))
assertEquals("A, B, C and D", foo(List("A","B","C","D")))
source
share