博客
关于我
codewars练习(javascript)-2021/5/6&7&8&9&10
阅读量:740 次
发布时间:2019-03-22

本文共 1153 字,大约阅读时间需要 3 分钟。

codewars-js练习

2021/5/6

【1】<7kyu>【Greatest common divisor】

求两个正整数的最大公约数

整数可以很大,所以你需要找到一个聪明的解决方案。

思路

一开始采用了简单粗暴的方式(代码如下),然后时间超时。

function mygcd(x, y) {    var i = Math.min(x, y);    var temp = [];    if (x == 1 && y == 1) return 1;    while (i >= 1) {        if (x % i == 0 && y % i == 0) return i;        i--;    }}
解决方法

后来采用了下面的辗转相除法,就通过了。

##### 原理如果有两个数a和b,b为0,那么a和b的最大公约数一定是a。那么就想尽办法让它出现0的情况。### 2021/5/7【1】<7kyu>【Sum of Triangular Numbers】#### 返回包括第n个三角形数在内的所有三角形数的和。##### 示例[01] 02 [03] 04 05 [06] 07 08 09 [10] 11 12 13 14 [15] 16 17 18 19 20 [21] 如果输入4,则返回1 + 3 + 6 + 10 = 20。##### 解决方法```javascript

2021/5/8

【1】<7kyu>【Invisible cubes】

问题描述

给定的n对应的不可见立方体数。

示例

输入:0输出:0输入:2输出:27

解决方法

【2】<6kyu>【Arabian String】

创建一个可以将字符串从不同格式转换为PascalCase的方法。这也必须支持符号。

示例

"example name" → "ExampleName""your-NaMe-here" → "YourNameHere""testing ABC" → "TestingAbc"

解决方法

2021/5/9

【1】<8kyu>【What’s the real floor?】

写一个函数,在美国系统中给定的楼层返回在欧洲系统中的楼层。

示例

1 → 02 → 0513 → 41514 → 13-316 → -3

解决方法

2021/5/10

【1】<8kyu>【Multiplication table for number】

返回一个从1到10的整数的乘法表。

示例

1 * 5 = 52 * 5 = 103 * 5 = 154 * 5 = 205 * 5 = 256 * 5 = 307 * 5 = 358 * 5 = 409 * 5 = 4510 * 5 = 50

解决方法

转载地址:http://oxdwk.baihongyu.com/

你可能感兴趣的文章
Python+Pytest+Allure+Git+Jenkins接口自动化框架
查看>>
python+pytest接口自动化 —— 参数关联
查看>>
python+pytest接口自动化 —— 参数关联
查看>>
Python+pytest接口自动化 —— 接口测试基础
查看>>
python+pytest接口自动化 —— 自动化用例编写思路 (使用pytest编写一个测试脚本)
查看>>
Python+pytest接口自动化之cookie绕过登录(保持登录状态)
查看>>
python+pytest接口自动化:接口测试
查看>>
Python+requests+unittest执行接口自动化测试详情
查看>>
Python+requests+unittest执行接口自动化测试详情
查看>>
python+requests+unittest执行自动化接口测试!
查看>>
Python+Requests编码识别Bug
查看>>
python函数编写_[零基础学python]传说中的函数编写条规
查看>>
Python+selenium —— UI自动化之鼠标操作
查看>>
python函数注释,参数后面加冒号:,函数后面的箭头→是什么?
查看>>
Python+Selenium+Threading进行兼容性测试
查看>>
Python+selenium+unittest的GUI自动化框架实现
查看>>
python函数拟合不规则曲线_Python计算&绘图——曲线拟合问题(转)
查看>>
python函数定义的基本格式_零基础学python-2.19 定义函数、调用函数与默认参数
查看>>
Python+Selenium之数据驱动测试的实现
查看>>
python函数定义与使用+返回值简解
查看>>