Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
码梦天涯
backend-utils
提交
dfc5e7a0
B
backend-utils
项目概览
码梦天涯
/
backend-utils
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
backend-utils
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
dfc5e7a0
编写于
12月 26, 2019
作者:
码梦天涯
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.MathUtil.randomNumBoth rename to MathUtil.randomBetween
2.Zip16Util.encode add toLowerCase at first time
上级
dee9d216
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
25 deletion
+23
-25
src/math-util.ts
src/math-util.ts
+22
-24
src/zip16-util.ts
src/zip16-util.ts
+1
-1
未找到文件。
src/math-util.ts
浏览文件 @
dfc5e7a0
import
{
VarUtil
}
from
"
./var-util
"
;
export
namespace
MathUtil
{
export
function
random
NumBoth
(
min
:
number
,
max
:
number
)
{
export
function
random
Between
(
min
:
number
,
max
:
number
)
{
const
range
=
max
-
min
;
const
rand
=
Math
.
random
();
return
min
+
Math
.
round
(
rand
*
range
);
...
...
@@ -68,10 +66,10 @@ export namespace MathUtil {
throw
Error
(
`
${
condition
}
is not valid`
);
}
const
result
:
ctk
[]
=
condition
.
map
(
exp
=>
VarUtil
.
isArray
(
exp
)
?
calc
(
exp
)
:
exp
);
const
result
:
ctk
[]
=
condition
.
map
(
exp
=>
Array
.
isArray
(
exp
)
?
calc
(
exp
)
:
exp
);
const
operator
=
result
.
shift
();
const
operate
=
getOperateFn
(
operator
);
const
operate
=
getOperateFn
(
operator
as
string
);
// console.log(JSON.stringify([operator, ...result]));
// console.log();
...
...
@@ -83,21 +81,6 @@ export namespace MathUtil {
return
Number
(
result
[
0
]);
}
function
getOperateFn
(
operator
:
string
)
{
switch
(
operator
)
{
case
"
+
"
:
return
MathUtil
.
add
;
case
"
-
"
:
return
MathUtil
.
sub
;
case
"
*
"
:
return
MathUtil
.
mul
;
case
"
/
"
:
return
MathUtil
.
div
;
default
:
throw
Error
(
`
${
operator
}
is not an operator`
);
}
}
/**
* 四则运算表达式求值 支持括号,+,-,*,/,但使用字符串时不支持负数
* 传入数组时,可以通过多级数组控制计算优先级
...
...
@@ -206,17 +189,32 @@ export namespace MathUtil {
return
outputQueue
;
}
function
getOperateFn
(
operator
:
string
)
{
switch
(
operator
)
{
case
"
+
"
:
return
add
;
case
"
-
"
:
return
sub
;
case
"
*
"
:
return
mul
;
case
"
/
"
:
return
div
;
default
:
throw
Error
(
`
${
operator
}
is not an operator`
);
}
}
function
getResult
(
fir
:
nos
,
sec
:
nos
,
cur
:
nos
)
{
let
result
;
switch
(
cur
)
{
case
"
+
"
:
result
=
MathUtil
.
add
(
fir
,
sec
);
break
;
result
=
add
(
fir
,
sec
);
break
;
case
"
-
"
:
result
=
MathUtil
.
sub
(
fir
,
sec
);
break
;
result
=
sub
(
fir
,
sec
);
break
;
case
"
*
"
:
result
=
MathUtil
.
mul
(
fir
,
sec
);
break
;
result
=
mul
(
fir
,
sec
);
break
;
case
"
/
"
:
result
=
MathUtil
.
div
(
fir
,
sec
);
break
;
result
=
div
(
fir
,
sec
);
break
;
default
:
throw
Error
(
"
invalid expression
"
);
}
...
...
src/zip16-util.ts
浏览文件 @
dfc5e7a0
...
...
@@ -45,7 +45,7 @@ export namespace Zip16Util {
* 对0~f进制的字符串按照进制转换规则执行编码
*/
export
function
encode
(
str
:
string
)
{
const
bin
=
binary
(
str
,
des4
,
hex
);
const
bin
=
binary
(
str
.
toLowerCase
()
,
des4
,
hex
);
return
[
source
(
bin
,
6
,
des6
,
zip
),
source
(
str
.
length
.
toString
(
2
),
6
,
des6
,
zip
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录