12's factors are: {1,2,3,4,6,12}

function factors (n) {
let list = []; for (let i = 1; i < Math.sqrt(n); i++) {
if (n % i === 0) {
list.push(i);
if (i !== Math.sqrt(n)) {
list.push(n / i);
}
}
} return list;
} factors(12) // [ 1, 12, 2, 6, 3, 4 ]

[Algorithm] Finding all factors of a number的更多相关文章

  1. [Algorithm] Finding Prime numbers - Sieve of Eratosthenes

    Given a number N, the output should be the all the prime numbers which is less than N. The solution ...

  2. [Algorithm] 4. Ugly Number II

    Description Ugly number is a number that only havefactors 2, 3 and 5. Design an algorithm to find th ...

  3. 2014辽宁ACM省赛 Prime Factors

    问题 L: Prime Factors 时间限制: 1 Sec  内存限制: 128 MB [提交][状态][论坛] 题目描写叙述 I'll give you a number , please te ...

  4. poj1142.Smith Number(数学推导)

    Smith Number Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 825  Solved: 366 Description While skimm ...

  5. WUSTOJ 1332: Prime Factors(Java)

    题目链接:1332: Prime Factors Description I'll give you a number , please tell me how many different prim ...

  6. Must practice programming questions in all languages

    To master any programming languages, you need to definitely solve/practice the below-listed problems ...

  7. [C1] Andrew Ng - AI For Everyone

    About this Course AI is not only for engineers. If you want your organization to become better at us ...

  8. Design and Analysis of Algorithms_Divide-and-Conquer

    I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...

  9. Working Set缓存算法(转)

    为了加深对缓存算法的理解,特转此篇,又由于本文内容过多,故不做翻译,原文地址Working Set页面置换算法 In the purest form of paging, processes are ...

随机推荐

  1. (4.35)sql server清理过期文件【转】

    在SQL Server中, 一般是用维护计划实现删除过期文件.不过直接用脚本也是可以的,而且更灵活. 下面介绍三种方法, 新建一个作业, 在作业的步骤里加上相关的脚本就可以了. --1. xp_del ...

  2. row_number()、rank()、dense_rank()排序方式的区别

    1.row_number() 排序策略,连续排序,它会为查询出来的每一行记录生成一个序号,依次排序且不会重复,例如1,2,3,4   SELECT names,dept,row_number() OV ...

  3. 【LOJ】#2983. 「WC2019」数树

    LOJ2983. 「WC2019」数树 task0 有\(i\)条边一样答案就是\(y^{n - i}\) task1 这里有个避免容斥的方法,如果有\(i\)条边重复我们要算的是\(y^{n - i ...

  4. python 高阶函数 lamdad reduce map

    ## def use_filer(l):## # 过滤偶数# rest = filter(lambda n: n % 2 != 0, l)# return rest## if __name__ == ...

  5. 从入门到自闭之Python--MySQL数据库安装

    分类: 关系型数据库:mysql oracle sqlserver sqllite 非关系型数据库:redis mongodb memcache hbase 安装: 网址:https://www.my ...

  6. Open-falcon监控

    https://book.open-falcon.org/zh_0_2/ 本文档记录了CentOS7.4下open-falcon-v2监控系统的部署流程,以及一些需要注意的地方. 环境准备 安装Red ...

  7. error: [Errno 13] Permission denied: '/usr/local/lib/处理方法

    在ubuntu系统下使用pip 命令安装包时,出现以下类似错误提示: error: [Errno 13] Permission denied: '/usr/local/lib/python2.7/di ...

  8. jenkins+docker+git+etcd实现应用配置文件管理

    两台机器: 一台机器安装gitlab: http://www.cnblogs.com/cjsblogs/p/8716932.html 另一台机器安装etcd+docker+jenkins jenkin ...

  9. Vasya and Endless Credits CodeForces - 1107F (二分图完美匹配)

    大意: n中贷款, 每种只能买一次, 第$i$种给$a_i$元, 要还款$k_i$个月, 每个月底还$b_i$元. 每个月可以在月初申请一种贷. 求某一时刻能得到的最大钱数.

  10. ubutnu18.04LTS 配置网卡新特性

    在Ubuntu16的时候配置网卡信息都是在 /etc/network/interfaces 下的,但是到了18,配置文件位置改为了/etc/netplan/*.yaml,配置配置内容如下: netwo ...