freeCodeCamp/curriculum/challenges/chinese/08-coding-interview-prep/rosetta-code/comma-quibbling.chinese.md

3.1 KiB
Raw Blame History

title id challengeType videoUrl localeTitle
Comma quibbling 596e414344c3b2872167f0fe 5 逗号狡猾

Description

Comma quibbling是Eric Lippert在他的博客中最初设定的任务。

任务:

编写一个函数来生成一个字符串输出,它是列表/序列中输入字的串联,其中:

没有单词的输入产生仅两个大括号字符“{}”的输出字符串。只有一个单词的输入,例如[“ABC”],会在两个大括号内产生单词的输出字符串,例如“{ABC}”。两个单词的输入,例如[“ABC”“DEF”],产生两个大括号内的两个单词的输出字符串,其中单词由字符串“和”分隔,例如“{ABC和DEF}”。三个或更多单词的输入,例如[“ABC”“DEF”“G”“H”],产生除了最后一个单词之外的所有输出字符串,用“,”分隔,最后一个单词用“和”分隔。 “并且都在括号内;例如“{ABCDEFG和H}”。

在此页面上显示输出的以下一系列输入测试您的功能:

[]#(无输入字)。 [“ABC”] [“ABC”“DEF”] [“ABC”“DEF”“G”“H”]

注意:假设此单词是此任务的非空字符串大写字符。

Instructions

Tests

tests:
  - text: <code>quibble</code>是一种功能。
    testString: 'assert(typeof quibble === "function", "<code>quibble</code> is a function.");'
  - text: '<code>quibble([&quot;ABC&quot;])</code>应该返回一个字符串。'
    testString: 'assert(typeof quibble(["ABC"]) === "string", "<code>quibble(["ABC"])</code> should return a string.");'
  - text: '<code>quibble([])</code>应返回“{}”。'
    testString: 'assert.equal(quibble(testCases[0]), results[0], "<code>quibble([])</code> should return "{}".");'
  - text: '<code>quibble([&quot;ABC&quot;])</code>应该返回“{ABC}”。'
    testString: 'assert.equal(quibble(testCases[1]), results[1], "<code>quibble(["ABC"])</code> should return "{ABC}".");'
  - text: '<code>quibble([&quot;ABC&quot;, &quot;DEF&quot;])</code>应返回“{ABC和DEF}”。'
    testString: 'assert.equal(quibble(testCases[2]), results[2], "<code>quibble(["ABC", "DEF"])</code> should return "{ABC and DEF}".");'
  - text: '<code>quibble([&quot;ABC&quot;, &quot;DEF&quot;, &quot;G&quot;, &quot;H&quot;])</code>应返回“{ABCDEFG和H}”。'
    testString: 'assert.equal(quibble(testCases[3]), results[3], "<code>quibble(["ABC", "DEF", "G", "H"])</code> should return "{ABC,DEF,G and H}".");'

Challenge Seed

function quibble (words) {
  // Good luck!
  return true;
}

After Test

console.info('after the test');

Solution

// solution required