蹄鉄の釘が1本足りないばかりに、王国が失われた。昔からそう言い伝えられています。
入力のリストが与えられたら、それに対応することわざを生成します。
たとえば、リスト["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.
入力のリストはさまざまであることに注意してください。解答は、任意の長さと内容のリストを扱える必要があります。 出力テキストのどの行も、固定された変わらない文字列であってはなりません。すべてが与えられた入力に応じて変化する必要があります。
リストの最後の要素がstringではなくobjectのとき、その要素には、ことわざの最後の行を修飾する修飾子が入ります。
proverb('nail', 'shoe', { qualifier: 'horseshoe' });
// => For want of a nail the shoe was lost.
// And all for the want of a horseshoe nail.
Exercismに登録すれば、37個のコンセプト159個の演習、そして本物の人間によるメンタリングとともに、JavaScriptを学んでマスターできます。すべて無料です。