Instruções

Entre vírgulas

<a href="https://rosettacode.org/wiki/Comma_quibbling" target="_blank" rel="noopener noreferrer nofollow">Comma quibbling</a> é uma tarefa originalmente proposta por Eric Lippert em seu blog.

O que fazer:

Escreva uma função para gerar uma saída de string que é a concatenação das palavras de entrada a partir de uma lista/sequência, onde: <ol> <li>An input of no words produces the output string of just the two brace characters (<code>"{}"</code>)</li> <li>An input of just one word, e.g. <code>["ABC"]</code>, produces the output string of the word inside the two braces, e.g. <code>"{ABC}"</code></li> <li>An input of two words, e.g. <code>["ABC", "DEF"]</code>, produces the output string of the two words inside the two braces with the words separated by the string <code>" and "</code>, e.g. <code>"{ABC and DEF}"</code></li> <li>An input of three or more words, e.g. <code>["ABC", "DEF", "G", "H"]</code>, produces the output string of all but the last word separated by <code>", "</code> with the last word separated by <code>" and "</code> and all within braces; e.g. <code>"{ABC, DEF, G and H}"</code></li> </ol> Teste sua função com a série de entradas a seguir mostrando a saída aqui nesta página: <ul> <li>[] # (No input words).</li> <li>["ABC"]</li> <li>["ABC", "DEF"]</li> <li>["ABC", "DEF", "G", "H"]</li> </ul> Nota: Assuma que as palavras são strings não vazias de caracteres maiúsculos para esta tarefa.

Critérios de Aceitação:

Testes:

  • `quibble` deve ser uma função.
  • `quibble(["ABC"])` deve retornar uma string.
  • `quibble([])` deve retornar "{}".
  • `quibble(["ABC"])` deve retornar `"{ABC}"`.
  • `quibble(["ABC", "DEF"])` deve retornar `"{ABC and DEF}"`.
  • `quibble(["ABC", "DEF", "G", "H"])` deve retornar `"{ABC, DEF, G and H}"`.

Console