Harshad或Niven数是正整数≥1,可以被它们的数字之和整除。
例如,42是Harshad数,因为42可以被(4 + 2)整除而没有余数。
假设系列被定义为按递增顺序排列的数字。任务:实现一个函数来生成Harshad序列的连续成员。
使用它列出序列的前20个成员并列出第一个大于1000的Harshad数。
isHarshadOrNiven
是一个函数。
testString: 'assert(typeof isHarshadOrNiven === "function", "isHarshadOrNiven
is a function.");'
- text: 'isHarshadOrNiven()
应该返回{"firstTwenty": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42],"firstOver1000": 1002}
'
testString: 'assert.deepEqual(isHarshadOrNiven(), res, "isHarshadOrNiven()
should return {"firstTwenty": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42],"firstOver1000": 1002}
");'
```