提交 dfc5e7a0 编写于 作者: 码梦天涯's avatar 码梦天涯

1.MathUtil.randomNumBoth rename to MathUtil.randomBetween

2.Zip16Util.encode add toLowerCase at first time
上级 dee9d216
import { VarUtil } from "./var-util";
export namespace MathUtil {
export function randomNumBoth(min: number, max: number) {
export function randomBetween(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");
}
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册