谚语

谚语

中等

说明

俗话说,只因少了一枚马蹄钉,一个王国便就此覆灭。

给定一组输入,生成相应的谚语。 例如,给定列表["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"],你需要输出这首谚语诗谣的完整内容:

For want of a nail the shoe was lost.
For want of a shoe the horse was lost.
For want of a horse the rider was lost.
For want of a rider the message was lost.
For want of a message the battle was lost.
For want of a battle the kingdom was lost.
And all for the want of a nail.

注意,输入的列表可能各不相同;你的解答应能处理任意长度和任意内容的列表。 输出文本的每一行都不应是固定不变的字符串,而应随给定的输入而变化。

实现

如果数组中的最后一个元素是object而不是string,它会包含一个限定词,用来修饰谚语的最后一行。

proverb('nail', 'shoe', { qualifier: 'horseshoe' });
// => For want of a nail the shoe was lost.
//    And all for the want of a horseshoe nail.

来源

Wikipedia链接会在新窗口或新标签页中打开
通过 GitHub 编辑 链接将在新窗口或新标签页中打开
JavaScript Exercism

准备好开始 谚语 了吗?

注册 Exercism,借助 37 个概念159 个练习 和真人导师指导,学习并掌握 JavaScript,全部免费。