2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
id: 597f1e7fbc206f0e9ba95dc4
|
2020-12-16 00:37:30 -07:00
|
|
|
title: 整数因子
|
2018-10-10 18:03:03 -04:00
|
|
|
challengeType: 5
|
|
|
|
|
videoUrl: ''
|
|
|
|
|
---
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --description--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
<p>编写一个返回正整数因子的函数。 </p><p>这些因子是正整数,通过该正整数可以将被分解的数量除以产生正整数结果。 </p> ///
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`factors`是一种功能。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
|
assert(typeof factors === 'function');
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`factors(45)`应该返回`[1,3,5,9,15,45]` 。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert.deepEqual(factors(45), ans[0]);
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`factors(53)`应该返回`[1,53]` 。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert.deepEqual(factors(53), ans[1]);
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`factors(64)`应该返回`[1,2,4,8,16,32,64]` 。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert.deepEqual(factors(64), ans[2]);
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --solutions--
|
|
|
|
|
|