提交 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 namespace MathUtil {
export function randomNumBoth(min: number, max: number) { export function randomBetween(min: number, max: number) {
const range = max - min; const range = max - min;
const rand = Math.random(); const rand = Math.random();
return min + Math.round(rand * range); return min + Math.round(rand * range);
...@@ -68,10 +66,10 @@ export namespace MathUtil { ...@@ -68,10 +66,10 @@ export namespace MathUtil {
throw Error(`${condition} is not valid`); 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 operator = result.shift();
const operate = getOperateFn(operator); const operate = getOperateFn(operator as string);
// console.log(JSON.stringify([operator, ...result])); // console.log(JSON.stringify([operator, ...result]));
// console.log(); // console.log();
...@@ -83,21 +81,6 @@ export namespace MathUtil { ...@@ -83,21 +81,6 @@ export namespace MathUtil {
return Number(result[0]); 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 { ...@@ -206,17 +189,32 @@ export namespace MathUtil {
return outputQueue; 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) { function getResult(fir: nos, sec: nos, cur: nos) {
let result; let result;
switch (cur) { switch (cur) {
case "+": case "+":
result = MathUtil.add(fir, sec); break; result = add(fir, sec); break;
case "-": case "-":
result = MathUtil.sub(fir, sec); break; result = sub(fir, sec); break;
case "*": case "*":
result = MathUtil.mul(fir, sec); break; result = mul(fir, sec); break;
case "/": case "/":
result = MathUtil.div(fir, sec); break; result = div(fir, sec); break;
default: default:
throw Error("invalid expression"); throw Error("invalid expression");
} }
......
...@@ -45,7 +45,7 @@ export namespace Zip16Util { ...@@ -45,7 +45,7 @@ export namespace Zip16Util {
* 对0~f进制的字符串按照进制转换规则执行编码 * 对0~f进制的字符串按照进制转换规则执行编码
*/ */
export function encode(str: string) { export function encode(str: string) {
const bin = binary(str, des4, hex); const bin = binary(str.toLowerCase(), des4, hex);
return [ return [
source(bin, 6, des6, zip), source(bin, 6, des6, zip),
source(str.length.toString(2), 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.
先完成此消息的编辑!
想要评论请 注册