mm_maths 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/README.md +28 -12
  2. package/index.js +6 -410
  3. package/lib/maths.js +429 -0
  4. package/package.json +42 -33
  5. package/tool/math/index.js +83 -0
  6. package/tool/math/tool.json +60 -0
  7. package/.gitattributes +0 -5
  8. package/convert/format_multiply/index.js +0 -40
  9. package/convert/format_multiply/test.js +0 -5
  10. package/convert/format_plus/index.js +0 -42
  11. package/convert/format_plus/test.js +0 -4
  12. package/convert/four_run/convert.json +0 -8
  13. package/convert/four_run/index.js +0 -20
  14. package/convert/four_run/test.js +0 -7
  15. package/convert/multiply_divide/index.js +0 -197
  16. package/convert/multiply_divide/test.js +0 -14
  17. package/convert/plus_subtract/index.js +0 -160
  18. package/convert/plus_subtract/test.js +0 -15
  19. package/convert/readme.md +0 -2
  20. package/doc/mm_math.doc +0 -0
  21. package/doc//345/207/275/346/225/260/347/254/246/345/217/267/344/270/200/350/247/210/350/241/250.xls +0 -0
  22. package/express/README.md +0 -2
  23. package/identities/chemistry/readme.md +0 -1
  24. package/identities/equation/readme.md +0 -2
  25. package/identities/geometry/readme.md +0 -1
  26. package/identities/geometry/rectangle/readme.md +0 -1
  27. package/identities/geometry/string/readme.md +0 -1
  28. package/identities/physics/readme.md +0 -1
  29. package/identities/readme.md +0 -2
  30. package/math/array/average/index.js +0 -10
  31. package/math/array/average/math.json +0 -8
  32. package/math/array/average/test.js +0 -3
  33. package/math/array/col/index.js +0 -17
  34. package/math/array/col/math.json +0 -8
  35. package/math/array/col/test.js +0 -4
  36. package/math/array/composite/index.js +0 -35
  37. package/math/array/composite/math.json +0 -8
  38. package/math/array/composite/test.js +0 -4
  39. package/math/array/deviations/index.js +0 -15
  40. package/math/array/deviations/math.json +0 -8
  41. package/math/array/deviations/test.js +0 -3
  42. package/math/array/difference/index.js +0 -9
  43. package/math/array/difference/math.json +0 -8
  44. package/math/array/difference/test.js +0 -7
  45. package/math/array/distinct/index.js +0 -20
  46. package/math/array/distinct/math.json +0 -8
  47. package/math/array/distinct/test.js +0 -8
  48. package/math/array/distributive/index.js +0 -24
  49. package/math/array/distributive/math.json +0 -8
  50. package/math/array/distributive/test.js +0 -3
  51. package/math/array/divisor/index.js +0 -17
  52. package/math/array/divisor/math.json +0 -8
  53. package/math/array/divisor/test.js +0 -6
  54. package/math/array/intersect/index.js +0 -9
  55. package/math/array/intersect/math.json +0 -8
  56. package/math/array/intersect/test.js +0 -7
  57. package/math/array/max/index.js +0 -17
  58. package/math/array/max/math.json +0 -8
  59. package/math/array/max/test.js +0 -8
  60. package/math/array/median/index.js +0 -34
  61. package/math/array/median/math.json +0 -8
  62. package/math/array/median/test.js +0 -4
  63. package/math/array/min/index.js +0 -16
  64. package/math/array/min/math.json +0 -8
  65. package/math/array/min/test.js +0 -8
  66. package/math/array/multiple/index.js +0 -17
  67. package/math/array/multiple/math.json +0 -8
  68. package/math/array/multiple/test.js +0 -7
  69. package/math/array/natural/index.js +0 -17
  70. package/math/array/natural/math.json +0 -8
  71. package/math/array/natural/test.js +0 -9
  72. package/math/array/pos/index.js +0 -21
  73. package/math/array/pos/math.json +0 -8
  74. package/math/array/pos/test.js +0 -41
  75. package/math/array/prime/index.js +0 -35
  76. package/math/array/prime/math.json +0 -8
  77. package/math/array/prime/test.js +0 -4
  78. package/math/array/readme.md +0 -5
  79. package/math/array/reduction/index.js +0 -57
  80. package/math/array/reduction/math.json +0 -8
  81. package/math/array/reduction/test.js +0 -42
  82. package/math/array/rising/index.js +0 -8
  83. package/math/array/rising/math.json +0 -8
  84. package/math/array/rising/test.js +0 -3
  85. package/math/array/row/index.js +0 -11
  86. package/math/array/row/math.json +0 -8
  87. package/math/array/row/test.js +0 -4
  88. package/math/array/square/index.js +0 -12
  89. package/math/array/square/math.json +0 -8
  90. package/math/array/square/test.js +0 -3
  91. package/math/array/stddev/index.js +0 -17
  92. package/math/array/stddev/math.json +0 -8
  93. package/math/array/stddev/test.js +0 -4
  94. package/math/array/sum/index.js +0 -13
  95. package/math/array/sum/math.json +0 -8
  96. package/math/array/sum/test.js +0 -3
  97. package/math/array/sumproduct/index.js +0 -13
  98. package/math/array/sumproduct/math.json +0 -8
  99. package/math/array/sumproduct/test.js +0 -3
  100. package/math/array/union/index.js +0 -11
  101. package/math/array/union/math.json +0 -8
  102. package/math/array/union/test.js +0 -7
  103. package/math/base/abs/index.js +0 -8
  104. package/math/base/abs/math.json +0 -8
  105. package/math/base/abs/test.js +0 -3
  106. package/math/base/ceil/index.js +0 -8
  107. package/math/base/ceil/math.json +0 -8
  108. package/math/base/ceil/test.js +0 -3
  109. package/math/base/denominator/index.js +0 -17
  110. package/math/base/denominator/math.json +0 -9
  111. package/math/base/denominator/test.js +0 -3
  112. package/math/base/diff/index.js +0 -9
  113. package/math/base/diff/math.json +0 -8
  114. package/math/base/diff/test.js +0 -6
  115. package/math/base/exp/index.js +0 -8
  116. package/math/base/exp/math.json +0 -8
  117. package/math/base/exp/test.js +0 -6
  118. package/math/base/floor/index.js +0 -8
  119. package/math/base/floor/math.json +0 -8
  120. package/math/base/floor/test.js +0 -3
  121. package/math/base/int/index.js +0 -8
  122. package/math/base/int/math.json +0 -8
  123. package/math/base/int/test.js +0 -2
  124. package/math/base/log/index.js +0 -8
  125. package/math/base/log/math.json +0 -8
  126. package/math/base/log/test.js +0 -4
  127. package/math/base/max_divisor/index.js +0 -10
  128. package/math/base/max_divisor/math.json +0 -9
  129. package/math/base/max_divisor/test.js +0 -3
  130. package/math/base/min_multiple/index.js +0 -11
  131. package/math/base/min_multiple/math.json +0 -9
  132. package/math/base/min_multiple/test.js +0 -3
  133. package/math/base/mod/index.js +0 -8
  134. package/math/base/mod/math.json +0 -8
  135. package/math/base/mod/test.js +0 -3
  136. package/math/base/pow/index.js +0 -9
  137. package/math/base/pow/math.json +0 -8
  138. package/math/base/pow/test.js +0 -3
  139. package/math/base/rand/index.js +0 -21
  140. package/math/base/rand/math.json +0 -8
  141. package/math/base/rand/test.js +0 -3
  142. package/math/base/random/index.js +0 -12
  143. package/math/base/random/math.json +0 -8
  144. package/math/base/random/test.js +0 -4
  145. package/math/base/readme.md +0 -1
  146. package/math/base/round/index.js +0 -14
  147. package/math/base/round/math.json +0 -8
  148. package/math/base/round/test.js +0 -4
  149. package/math/base/sqrt/index.js +0 -8
  150. package/math/base/sqrt/math.json +0 -8
  151. package/math/base/sqrt/test.js +0 -5
  152. package/math/readme.md +0 -1
  153. package/math/stock/AMOUNT/index.js +0 -7
  154. package/math/stock/AMOUNT/math.json +0 -8
  155. package/math/stock/AMOUNT/test.js +0 -4
  156. package/math/stock/AP/index.js +0 -20
  157. package/math/stock/AP/math.json +0 -8
  158. package/math/stock/AP/test.js +0 -5
  159. package/math/stock/AROON/index.js +0 -14
  160. package/math/stock/ARR/index.js +0 -10
  161. package/math/stock/ARR/math.json +0 -8
  162. package/math/stock/ARR/test.js +0 -45
  163. package/math/stock/ASTAR/index.js +0 -20
  164. package/math/stock/ASTAR/math.json +0 -8
  165. package/math/stock/ASTAR/test.js +0 -4
  166. package/math/stock/AVERAGE/index.js +0 -14
  167. package/math/stock/AVERAGE/math.json +0 -8
  168. package/math/stock/AVERAGE/test.js +0 -5
  169. package/math/stock/AYANG/index.js +0 -18
  170. package/math/stock/AYANG/math.json +0 -8
  171. package/math/stock/AYANG/test.js +0 -4
  172. package/math/stock/AYIN/index.js +0 -18
  173. package/math/stock/AYIN/math.json +0 -8
  174. package/math/stock/AYIN/test.js +0 -4
  175. package/math/stock/BBANDS/index.js +0 -0
  176. package/math/stock/BETWEEN/index.js +0 -24
  177. package/math/stock/BETWEEN/math.json +0 -8
  178. package/math/stock/BETWEEN/test.js +0 -4
  179. package/math/stock/CLOSE/c.js +0 -0
  180. package/math/stock/CLOSE/index.js +0 -11
  181. package/math/stock/CLOSE/math.json +0 -8
  182. package/math/stock/CLOSE/test.js +0 -45
  183. package/math/stock/CP/index.js +0 -35
  184. package/math/stock/CP/math.json +0 -8
  185. package/math/stock/CP/test.js +0 -5
  186. package/math/stock/CROSS/index.js +0 -29
  187. package/math/stock/CROSS/math.json +0 -8
  188. package/math/stock/CROSS/test.js +0 -6
  189. package/math/stock/DATE/index.js +0 -14
  190. package/math/stock/DATE/math.json +0 -8
  191. package/math/stock/DATE/test.js +0 -45
  192. package/math/stock/DOWN/index.js +0 -19
  193. package/math/stock/DOWN/math.json +0 -8
  194. package/math/stock/DOWN/test.js +0 -8
  195. package/math/stock/DOWNNDAY/index.js +0 -27
  196. package/math/stock/DOWNNDAY/math.json +0 -8
  197. package/math/stock/DOWNNDAY/test.js +0 -10
  198. package/math/stock/EMA/index.js +0 -30
  199. package/math/stock/EMA/math.json +0 -8
  200. package/math/stock/EMA/test.js +0 -4
  201. package/math/stock/HHV/index.js +0 -16
  202. package/math/stock/HHV/math.json +0 -8
  203. package/math/stock/HHV/test.js +0 -4
  204. package/math/stock/HIGH/h.js +0 -0
  205. package/math/stock/HIGH/index.js +0 -11
  206. package/math/stock/HIGH/math.json +0 -8
  207. package/math/stock/HIGH/test.js +0 -45
  208. package/math/stock/LEFT/index.js +0 -13
  209. package/math/stock/LEFT/math.json +0 -8
  210. package/math/stock/LEFT/test.js +0 -4
  211. package/math/stock/LLV/index.js +0 -16
  212. package/math/stock/LLV/math.json +0 -8
  213. package/math/stock/LLV/test.js +0 -4
  214. package/math/stock/LOW/index.js +0 -11
  215. package/math/stock/LOW/l.js +0 -0
  216. package/math/stock/LOW/math.json +0 -8
  217. package/math/stock/LOW/test.js +0 -47
  218. package/math/stock/MA/index.js +0 -30
  219. package/math/stock/MA/math.json +0 -8
  220. package/math/stock/MA/test.js +0 -5
  221. package/math/stock/MACD/index.js +0 -29
  222. package/math/stock/MACD/math.json +0 -8
  223. package/math/stock/MACD/test.js +0 -4
  224. package/math/stock/MFI/index.js +0 -33
  225. package/math/stock/NMA/index.js +0 -23
  226. package/math/stock/NMA/math.json +0 -8
  227. package/math/stock/NMA/test.js +0 -5
  228. package/math/stock/NOT/index.js +0 -7
  229. package/math/stock/NOT/math.json +0 -8
  230. package/math/stock/NOT/test.js +0 -10
  231. package/math/stock/OPEN/index.js +0 -11
  232. package/math/stock/OPEN/math.json +0 -8
  233. package/math/stock/OPEN/o.js +0 -0
  234. package/math/stock/OPEN/test.js +0 -45
  235. package/math/stock/PERCPRICEOSC/index.js +0 -19
  236. package/math/stock/REF/index.js +0 -15
  237. package/math/stock/REF/math.json +0 -8
  238. package/math/stock/REF/test.js +0 -5
  239. package/math/stock/RIGHT/index.js +0 -13
  240. package/math/stock/RIGHT/math.json +0 -8
  241. package/math/stock/RIGHT/test.js +0 -4
  242. package/math/stock/RSI/index.js +0 -36
  243. package/math/stock/SMA/index.js +0 -12
  244. package/math/stock/STAR/index.js +0 -19
  245. package/math/stock/STAR/math.json +0 -8
  246. package/math/stock/STAR/test.js +0 -4
  247. package/math/stock/STOCHRSI/index.js +0 -19
  248. package/math/stock/SUM/index.js +0 -19
  249. package/math/stock/SUM/math.json +0 -8
  250. package/math/stock/SUM/test.js +0 -7
  251. package/math/stock/TIME/index.js +0 -14
  252. package/math/stock/TIME/math.json +0 -8
  253. package/math/stock/TIME/test.js +0 -45
  254. package/math/stock/TRUERANGE/index.js +0 -19
  255. package/math/stock/UP/index.js +0 -19
  256. package/math/stock/UP/math.json +0 -8
  257. package/math/stock/UP/test.js +0 -9
  258. package/math/stock/UPNDAY/index.js +0 -28
  259. package/math/stock/UPNDAY/math.json +0 -8
  260. package/math/stock/UPNDAY/test.js +0 -10
  261. package/math/stock/VMA/index.js +0 -41
  262. package/math/stock/VMA/math.json +0 -8
  263. package/math/stock/VMA/test.js +0 -7
  264. package/math/stock/VOL/index.js +0 -11
  265. package/math/stock/VOL/math.json +0 -8
  266. package/math/stock/VOL/test.js +0 -45
  267. package/math/stock/WILLR/index.js +0 -22
  268. package/math/stock/YANG/index.js +0 -16
  269. package/math/stock/YANG/math.json +0 -8
  270. package/math/stock/YANG/test.js +0 -4
  271. package/math/stock/YIN/index.js +0 -16
  272. package/math/stock/YIN/math.json +0 -8
  273. package/math/stock/YIN/test.js +0 -4
  274. package/math/stock/readme.md +0 -294
  275. package/math/trigonometric/cos/index.js +0 -8
  276. package/math/trigonometric/cos/math.json +0 -20
  277. package/math/trigonometric/cot/index.js +0 -8
  278. package/math/trigonometric/cot/math.json +0 -17
  279. package/math/trigonometric/csc/index.js +0 -8
  280. package/math/trigonometric/csc/math.json +0 -20
  281. package/math/trigonometric/readme.md +0 -2
  282. package/math/trigonometric/sec/index.js +0 -8
  283. package/math/trigonometric/sec/math.json +0 -20
  284. package/math/trigonometric/sin/index.js +0 -8
  285. package/math/trigonometric/sin/math.json +0 -20
  286. package/math/trigonometric/tan/index.js +0 -8
  287. package/math/trigonometric/tan/math.json +0 -18
  288. package/symbol/brackets/index.js +0 -46
  289. package/symbol/brackets/symbol.json +0 -8
  290. package/symbol/brackets/test.js +0 -12
  291. package/symbol/decimal/index.js +0 -41
  292. package/symbol/decimal/symbol.json +0 -8
  293. package/symbol/decimal/test.js +0 -2
  294. package/symbol/percentage/index.js +0 -48
  295. package/symbol/percentage/symbol.json +0 -8
  296. package/symbol/percentage/test.js +0 -2
  297. package/symbol/pi/index.js +0 -20
  298. package/symbol/pi/symbol.json +0 -9
  299. package/symbol/pi/test.js +0 -2
  300. package/symbol/power/index.js +0 -111
  301. package/symbol/power/symbol.json +0 -8
  302. package/symbol/power/test.js +0 -10
  303. package/symbol/readme.md +0 -2
  304. package/test.js +0 -32
  305. package/test2.js +0 -47
@@ -1,42 +0,0 @@
1
- /**
2
- * 公式的加法格式化
3
- * @param {String} expression
4
- * @return {String} 返回格式化后的公式
5
- */
6
- module.exports = function format_plus(expression) {
7
- var exp = expression.replace(/\^\-/g, '^@');
8
- exp = exp.replace(/\+/g, ' +').replace(/\-/g, ' -');
9
- exp = exp.replace(/\^@/g, '^-');
10
- if (/[a-zA-Z]/.test(exp)) {
11
- var left = "";
12
- var between = "";
13
- var right = "";
14
- var value = "";
15
- var vals = exp.split(' ');
16
- var len = vals.length;
17
- for (var i = 0; i < len; i++) {
18
- var val = vals[i];
19
- if (/[a-zA-Z]/.test(val)) {
20
- if (val.indexOf('-') === -1) {
21
- left += ' ' + val;
22
- } else {
23
- between += ' ' + val;
24
- }
25
- } else {
26
- var k = val.replace(/\+/g, '').replace(/\-/g, '').replace(/\*/g, '');
27
- if (/^[0-9.]+$/.test(k)) {
28
- value += ' ' + val;
29
- } else {
30
- right += ' ' + val;
31
- }
32
- }
33
- }
34
- exp = left + ' +' + between + ' +' + right;
35
- if (value) {
36
- exp += ' +' + eval(value);
37
- }
38
- }
39
- return exp.replace('+ +', '+').replace('+ +', '+').replace('+ -', '-').replace('+ -', '-');
40
- };
41
-
42
- // .replace(/\*/g, ' *')
@@ -1,4 +0,0 @@
1
- const format_plus = require('./index');
2
- // console.log(format_plus('a+0.25+1/2a+0.75+1*2a+150.15-15.00'));
3
-
4
- console.log(format_plus('a+0.25+1/2a+0.75+1*2a+150+15%-15%-1/7'));
@@ -1,8 +0,0 @@
1
- {
2
- "key": "four_run",
3
- "name": "four run",
4
- "title": "四则运算",
5
- "descarption": "将式子做加减乘除变形",
6
- "func_file": "./index.js",
7
- "sort": 10
8
- }
@@ -1,20 +0,0 @@
1
- const multiply_divide = require('../multiply_divide');
2
- const plus_subtract = require('../plus_subtract');
3
-
4
- const decimal = require('../../symbol/decimal');
5
- const percentage = require('../../symbol/percentage');
6
-
7
- /**
8
- * @description 四则运算
9
- * @param {String} expression 公式
10
- */
11
- module.exports = function four_run(expression) {
12
- var express = decimal(expression);
13
- express = percentage(express);
14
- express = plus_subtract(express);
15
- express = express.replace(/\^\-/g, '^@').replace(/\+/g, '+ ').replace(/\-/g, '- ').replace(/\^@/g, '^-');
16
- if(express.indexOf('- ') == 0){
17
- express = express.replace('- ', '-')
18
- }
19
- return express;
20
- }
@@ -1,7 +0,0 @@
1
- const four_run = require('./index');
2
-
3
- var t = '4*a+1/2*3-3+b*a/2+b-b';
4
- var t = '4*a^3 + 3 - 2 + 1';
5
- var t = '4/a^-3 + 3 - 2 + 1 - 0.5a - a_2^2 * a_2^4';
6
- var t = '3 - 2 + 1 - 1 * 4^2 + 0.2';
7
- console.log(four_run(t));
@@ -1,197 +0,0 @@
1
- require('mm_expand');
2
- const power = require('../../symbol/power');
3
- const denominator = require('../../math/base/denominator');
4
-
5
- /**
6
- * 乘除
7
- * @param {String} expression 公式
8
- */
9
- function multiply_divide(expression) {
10
- var expres = power(expression);
11
- expres = expres.replace(/ /g, '').replace(/\*/g, ' *').replace(/\//g, ' /');
12
- var arr = expres.split(' ');
13
- // 统计代数
14
- var dict = {};
15
- var exp = "";
16
- // 乘*乘 / (除 * 除)
17
- var multiply = 1;
18
- var divide = 1;
19
- // 统计代数个数
20
- arr.map(function(str) {
21
- var k = str.replace('*', '').replace('/', '');
22
- k = k.left('^', true);
23
- if (isNaN(k)) {
24
- // 次方加减
25
- if (str.indexOf('^') !== -1) {
26
- var n = Number(str.right('^'));
27
- var ar = k.match(/[a-zA-Z]/);
28
- var len = ar.length;
29
- for (var i = 0; i < len; i++) {
30
- var ki = ar[i];
31
- if (!dict.hasOwnProperty(ki)) {
32
- dict[ki] += 0;
33
- }
34
- if (str.indexOf('/') !== -1) {
35
- dict[ki] += -1;
36
- } else {
37
- dict[ki] += 1;
38
- }
39
- }
40
- var ar = k.split(/[a-zA-Z]+/);
41
- const l = ar.length;
42
- for (var i = 0; i < l; i++) {
43
- var m = ar[i];
44
- if (str.indexOf('/') !== -1) {
45
- if (multiply % m === 0) {
46
- multiply = multiply / m;
47
- } else {
48
- divide = divide * m;
49
- }
50
- } else {
51
- multiply = multiply * m;
52
- }
53
- }
54
- } else {
55
- if (k.indexOf('_') === -1) {
56
- // console.log(k);
57
- var ar = k.split(/[a-zA-Z]+/);
58
- if (ar) {
59
- var len = ar.length;
60
- for (var i = 0; i < len; i++) {
61
- var txt = ar[i];
62
- if (txt) {
63
- var m = Number(txt);
64
- // 让乘数相乘,除数相乘
65
- if (str.indexOf('/') !== -1) {
66
- if (multiply % m === 0) {
67
- multiply = multiply / m;
68
- } else {
69
- divide = divide * m;
70
- }
71
- } else {
72
- multiply = multiply * m;
73
- }
74
- }
75
- }
76
- }
77
- var ar_k = k.match(/[a-zA-Z]/g, '');
78
- if (ar_k) {
79
- // 增减代数次方
80
- for (var i = 0; i < ar_k.length; i++) {
81
- var v = ar_k[i];
82
- if (!dict.hasOwnProperty(v)) {
83
- dict[v] = 0;
84
- }
85
- if (str.indexOf('/') !== -1) {
86
- dict[v] -= 1;
87
- } else {
88
- dict[v] += 1;
89
- }
90
- }
91
- }
92
- } else {
93
- if (!dict.hasOwnProperty(k)) {
94
- dict[k] = 0;
95
- }
96
- if (str.indexOf('/') !== -1) {
97
- dict[k] -= 1;
98
- } else {
99
- dict[k] += 1;
100
- }
101
- }
102
- }
103
- } else {
104
- var m = 1;
105
- if (str.indexOf('^') !== -1) {
106
- var n = Number(str.right('^'));
107
- var x = Number(k);
108
- m = Math.pow(x, n);
109
- } else {
110
- m = Number(k);
111
- }
112
- if (str.indexOf('/') != -1) {
113
- if (multiply % m === 0) {
114
- multiply = multiply / m;
115
- } else {
116
- divide = divide * m;
117
- }
118
- } else {
119
- multiply = multiply * m;
120
- }
121
- }
122
- });
123
- if (multiply === 0 || divide === 0) {
124
- return 0;
125
- }
126
- var bl = false;
127
- var left = "";
128
- if (multiply % divide === 0) {
129
- var shan = (multiply / divide);
130
- if (shan !== 1) {
131
- left = shan + '';
132
- }
133
- bl = true;
134
- } else {
135
- var param = denominator(multiply, divide);
136
- multiply = param.multiply;
137
- divide = param.divide;
138
- }
139
-
140
- var right = "";
141
- // 合并公式
142
- for (var k in dict) {
143
- var val = dict[k];
144
- if (val === 1) {
145
- left += k
146
- } else if (val !== 0) {
147
- if (val > 0) {
148
- left += " * " + k + '^' + val + " * "
149
- } else {
150
- var n = -val;
151
- if (n === 1) {
152
- right += k
153
- } else {
154
- right += " / " + k + '^' + n + " / "
155
- }
156
- }
157
- }
158
- }
159
- if(left.startsWith(' * ')){
160
- left = left.substring(3);
161
- }
162
- if(right.endWith(' / ')){
163
- right = right.substring(0,right.length - 3);
164
- }
165
-
166
- var result = "";
167
- if (!bl) {
168
- if (multiply !== 1) {
169
- result = multiply + left;
170
- } else {
171
- result = left;
172
- }
173
- if (divide !== 1) {
174
- result += '/' + divide + right;
175
- } else {
176
- result += '/' + right;
177
- }
178
- } else {
179
- if (right) {
180
- result = left + '/' + right;
181
- } else {
182
- result = left;
183
- if (!result) {
184
- result = "1";
185
- }
186
- }
187
- }
188
- if (result.indexOf('/') === 0) {
189
- result = 1 + result;
190
- }
191
- if(result.endsWith(' * ')){
192
- result = result.substring(0, result.length - 3);
193
- }
194
- return result.replace('* /', '/').replace(/\* \*/g, '*');
195
- };
196
-
197
- module.exports = multiply_divide;
@@ -1,14 +0,0 @@
1
- const multiply_divide = require('./index');
2
-
3
- // console.log(multiply_divide('4*a/3*a/c/4*3*b'));
4
- // console.log(multiply_divide('4*a/2*a/4/c'));
5
- // console.log(multiply_divide('4*a/2*3*b/a*c/b*c/b*c^3'));
6
- // console.log(multiply_divide('4^3*12/3a'));
7
-
8
- // console.log(multiply_divide("ab/8a^2"));
9
-
10
-
11
- // console.log(multiply_divide("ab/8a^2/2b^-3"));
12
-
13
-
14
- console.log(multiply_divide("ab/8a^2 * 2b^-3"));
@@ -1,160 +0,0 @@
1
- const multiply_divide = require('../multiply_divide');
2
- const denominator = require('../../math/base/denominator');
3
-
4
- /**
5
- * 加减
6
- * @param {String} expression 公式
7
- */
8
- module.exports = function plus_subtract(expression) {
9
- var expres = expression.replace(/\^\-/g, '^~');
10
- expres = expres.replace(/ /g, '').replace(/\+/g, ' +').replace(/\-/g, ' -');
11
- expres = expres.replace(/\^~/g, '^-');
12
- var arr = expres.split(' ');
13
-
14
- var dict = {};
15
- var exp = "";
16
- var num = 0;
17
-
18
- var multiply = 0;
19
- var divide = 1;
20
-
21
- var multiply_str = "";
22
- var divide_str = "";
23
-
24
- // 统计代数个数
25
- arr.map(function(x) {
26
- var exp = "";
27
-
28
- if (x.indexOf('-') === 0) {
29
- exp = " -" + multiply_divide(x.replace('-', '')) + "";
30
- } else {
31
- if (x.indexOf('+') === 0) {
32
- exp = x.replace('+', '');
33
- } else {
34
- exp = x;
35
- }
36
- exp = multiply_divide(exp) + "";
37
- }
38
- if (/[a-zA-Z]/.test(exp)) {
39
- if (exp.indexOf(' -') === 0) {
40
- if (exp.indexOf('^') !== -1 || exp.indexOf('/') !== -1) {
41
- var key = exp.replace(' -', '');
42
- // 代数加减
43
- if (!dict[key]) {
44
- dict[key] = -1;
45
- } else {
46
- dict[key] -= 1;
47
- }
48
- } else {
49
- var key = exp.match(/[a-zA-Z]+/)[0];
50
- var str = exp.replace(key, '');
51
- var n = 1;
52
- if(str)
53
- {
54
- if(str.trim() == '-')
55
- {
56
- n = -1;
57
- }
58
- else {
59
- n = Number(str);
60
- }
61
- }
62
- // 代数加减
63
- if (!dict[key]) {
64
- dict[key] = n;
65
- } else {
66
- dict[key] += n;
67
- }
68
- }
69
- } else {
70
- if (exp.indexOf('^') !== -1 || exp.indexOf('/') !== -1) {
71
- var key = exp;
72
- // 代数加减
73
- if (!dict[key]) {
74
- dict[key] = 1;
75
- } else {
76
- dict[key] += 1;
77
- }
78
- } else {
79
- var key = exp.match(/[a-zA-Z]+/)[0];
80
- var str = exp.replace(key, '');
81
- var n = 1;
82
- if(str)
83
- {
84
- if(str.trim() == '-')
85
- {
86
- n = -1;
87
- }
88
- else {
89
- n = Number(str);
90
- }
91
- }
92
- // 代数加减
93
- if (!dict[key]) {
94
- dict[key] = n;
95
- } else {
96
- dict[key] += n;
97
- }
98
- }
99
- }
100
- } else {
101
- // 代数加减
102
- if (exp.indexOf("^") !== -1) {
103
- var mh = exp.match(/[0-9]+\^[0-9]+/);
104
- if (mh) {
105
- var key = mh[0];
106
- var left = key.left("^");
107
- var ex = "";
108
- var right = key.right("^");
109
- var n = Number(right);
110
- for (var i = 0; i < n; i++) {
111
- ex += " * (" + left + ")";
112
- }
113
- var value = eval(ex.replace(' * ', ''));
114
- exp = exp.replace(key, value);
115
- }
116
- }
117
- if (exp.indexOf("/") !== -1) {
118
- var left = exp.left("/");
119
- var right = exp.right("/");
120
- var d = Number(right);
121
- multiply = Number(left) * divide + multiply * d;
122
- divide *= d;
123
- } else {
124
- num += Number(exp);
125
- }
126
- }
127
- });
128
-
129
- var result = '';
130
- // 合并公式
131
- for (var k in dict) {
132
- var val = dict[k];
133
- if (val === 1) {
134
- result += ' +' + k
135
- } else if (val !== 0) {
136
- if (val > 0) {
137
- result += ' +' + val + k
138
- } else {
139
- if (-val === 1) {
140
- result += ' -' + k
141
- } else {
142
- result += val + k
143
- }
144
- }
145
- }
146
- }
147
- if (num > 0) {
148
- result += ' +' + num
149
- } else if (num < 0) {
150
- result += num
151
- }
152
- if (multiply !== 0) {
153
- var o = denominator(multiply, divide);
154
- result += " +" + o.multiply + '/' + o.divide;
155
- }
156
- if (result.indexOf(' +') === 0) {
157
- result = result.replace(' +', '');
158
- }
159
- return result.replace(/\+ \-/g, ' -');
160
- };
@@ -1,15 +0,0 @@
1
- const plus_subtract = require('./index');
2
-
3
- // console.log(plus_subtract('4+a+2-3+b+a+b-b'));
4
- // console.log(plus_subtract('4*a/3-a/c/4+3*b'));
5
- // console.log(plus_subtract('4+a/2*a+4/c'));
6
-
7
- // console.log(plus_subtract('4+a/2a*2a/a'));
8
- // console.log(plus_subtract('4+a/2a + 1/7 +1/7'));
9
- // console.log(plus_subtract('4+a/7a + a/8a'));
10
- // console.log(plus_subtract('4+a/7a + ab/8a'));
11
-
12
- // console.log(plus_subtract('4 + 0 + 0.25 + 4^2 + 1/7 + 1/14'));
13
- // console.log(plus_subtract('4+a/7a + ab/8a^2 + 4^2 + 1/7 + 1/14'));
14
-
15
- console.log(plus_subtract('2a-3a + 4a'));
package/convert/readme.md DELETED
@@ -1,2 +0,0 @@
1
- # 转换函数
2
- 用于替换单个数值 或 短式
package/doc/mm_math.doc DELETED
Binary file
package/express/README.md DELETED
@@ -1,2 +0,0 @@
1
- # 数学公式
2
- 运用于 物理或几何的公式
@@ -1 +0,0 @@
1
- # 化学恒等式
@@ -1,2 +0,0 @@
1
- # 方程式恒等式
2
- 含一元一次,一元二次,一元三次等
@@ -1 +0,0 @@
1
- # 几何恒等式
@@ -1 +0,0 @@
1
- # 矩形恒等式
@@ -1 +0,0 @@
1
- # 线性恒等式
@@ -1 +0,0 @@
1
- # 物理恒等式
@@ -1,2 +0,0 @@
1
- # 恒等式库
2
- 用于替换恒等式
@@ -1,10 +0,0 @@
1
- const sum = require('../sum');
2
-
3
- /**
4
- * 求平均值
5
- * @param {Array} arr 数组
6
- * @return {Number} 返回平均值
7
- */
8
- module.exports = function average(arr) {
9
- return sum(arr) / arr.length;
10
- };
@@ -1,8 +0,0 @@
1
- {
2
- "key": "average",
3
- "name": "average",
4
- "title": "平均值",
5
- "group": "array",
6
- "type": "base",
7
- "func_file": "./index.js"
8
- }
@@ -1,3 +0,0 @@
1
- const average = require('./index');
2
- console.log(average([1, 2, 3, 4, 5]));
3
- console.log(average([21, 37, 25, 36, 23.5]));
@@ -1,17 +0,0 @@
1
- /**
2
- * 二维数组取列值
3
- * @param {Array} arr 二维数组
4
- * @param {Number} y 列
5
- * @return {Array} 返回列值集合
6
- */
7
- module.exports = function col(arr, y) {
8
- var arr_new = [];
9
- var len = arr.length;
10
- for (var i = 0; i < len; i++) {
11
- var arr_sub = arr[i];
12
- if (arr_sub.length >= y) {
13
- arr_new.push(arr_sub[y - 1]);
14
- }
15
- }
16
- return arr_new;
17
- };
@@ -1,8 +0,0 @@
1
- {
2
- "key": "col",
3
- "name": "column",
4
- "title": "取二维数组指定列值",
5
- "group": "array",
6
- "type": "base",
7
- "func_file": "./index.js"
8
- }
@@ -1,4 +0,0 @@
1
- const col = require('./index');
2
- var arr = [[15, 35, 68, 66],[38, 35, 68],[25, 35, 22, 33]];
3
- console.log(col(arr, 3));
4
- console.log(col(arr, 4));
@@ -1,35 +0,0 @@
1
- function isComposite(n) {
2
- if (n == 0 || n == 1) {
3
- return false;
4
- }
5
- if (n == 2) {
6
- return false;
7
- }
8
- var times = Math.sqrt(n);
9
- if (times == parseInt(times)) {
10
- return true;
11
- }
12
- for (var i = 2; i < times; i++) {
13
- if (n % i == 0) {
14
- return true;
15
- }
16
- }
17
- return false;
18
- }
19
-
20
- /**
21
- * 取所有合数
22
- * @param {Array} arr 数组
23
- * @return {Array} 返回合数集合
24
- */
25
- module.exports = function composite(arr) {
26
- var arr_new = [];
27
- var len = arr.length;
28
- for (var i = 0; i < len; i++) {
29
- var n = arr[i];
30
- if (isComposite(n)) {
31
- arr_new.push(n);
32
- }
33
- }
34
- return arr_new;
35
- };
@@ -1,8 +0,0 @@
1
- {
2
- "key": "composite",
3
- "name": "composite number",
4
- "title": "获取所有合数",
5
- "group": "fraction",
6
- "type": "base",
7
- "func_file": "./index.js"
8
- }
@@ -1,4 +0,0 @@
1
- const prime = require('./index');
2
- console.log(prime([4, 6, 8, 9, 11, 10103]));
3
- console.log(prime([0, 1, 2, 3, 4, 18]));
4
- console.log(prime([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 100]));
@@ -1,15 +0,0 @@
1
- const average = require('../average');
2
-
3
- /**
4
- * 求偏差
5
- * @param {Array} arr 数组
6
- * @return {Number} 返回平均值
7
- */
8
- module.exports = function deviations(arr) {
9
- // 先求平均值
10
- var value = average(arr);
11
- // 用当前数值减去平均值,求出偏差值
12
- return arr.map(function(x) {
13
- return x - value;
14
- });
15
- };
@@ -1,8 +0,0 @@
1
- {
2
- "key": "deviations",
3
- "name": "deviations",
4
- "title": "求偏差值",
5
- "group": "array",
6
- "type": "base",
7
- "func_file": "./index.js"
8
- }
@@ -1,3 +0,0 @@
1
- const deviations = require('./index');
2
- console.log(deviations([1, 2, 3, 4, 5]));
3
- console.log(deviations([21, 37, 25, 36, 23.5]));
@@ -1,9 +0,0 @@
1
- /**
2
- * 差集
3
- * @param {Array} arr_1
4
- * @param {Array} arr_2
5
- * @return {Array} 返回不含arr_2数值的数组
6
- */
7
- module.exports = function distinct(arr_1, arr_2) {
8
- return arr_1.filter(function(v){ return arr_2.indexOf(v) === -1 })
9
- };
@@ -1,8 +0,0 @@
1
- {
2
- "key": "difference",
3
- "name": "difference",
4
- "title": "差集",
5
- "group": "fraction",
6
- "type": "base",
7
- "func_file": "./index.js"
8
- }