7kyu Multiplication - Generators #2

题目:

Generators can be used to wonderful things. You can use them for numerous things, but here is one specific example. You are studying for a test so you must practice your multiplication, but you don't have a multiplication table showing the different examples. You have decided to create a generator that prints out a limitless list of time tables.

发电机可以用来做奇妙的事情。你可以用它们来做很多事情,但这里有一个具体的例子。你在为一个测试而学习,所以你必须练习乘法,但是你没有一个乘法表来显示不同的例子。您已经决定创建一个生成器,它打印出一个无限的时间表列表。

Task

Your generator must take one parameter a then everytime the generator is called you must return a string in the format of: 'a x b = c' where c is the answer. Also, the value of b, which starts at 1, must increment by 1 each time!

您的生成器必须接受一个参数,然后每次调用生成器时,必须以“a x b=c”的格式返回一个字符串,其中c就是答案。同样,从1开始的b的值必须每次递增1!

Sample Tests:

Test.describe("Fixed Tests", _ => {
  var gen = generator(1);
  Test.assertEquals(gen.next().value, '1 x 1 = 1', '1 x 1 = 1')
  Test.assertEquals(gen.next().value, '1 x 2 = 2', '1 x 2 = 2')
  Test.assertEquals(gen.next().value, '1 x 3 = 3', '1 x 3 = 3')
  Test.assertEquals(gen.next().value, '1 x 4 = 4', '1 x 4 = 4')
  Test.assertEquals(gen.next().value, '1 x 5 = 5', '1 x 5 = 5')
});

 

答案:

 

posted @ 2017-08-16 17:15  tong24  阅读(175)  评论(0编辑  收藏  举报