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.
- package/README.md +28 -12
- package/index.js +6 -410
- package/lib/maths.js +429 -0
- package/package.json +42 -33
- package/tool/math/index.js +83 -0
- package/tool/math/tool.json +60 -0
- package/.gitattributes +0 -5
- package/convert/format_multiply/index.js +0 -40
- package/convert/format_multiply/test.js +0 -5
- package/convert/format_plus/index.js +0 -42
- package/convert/format_plus/test.js +0 -4
- package/convert/four_run/convert.json +0 -8
- package/convert/four_run/index.js +0 -20
- package/convert/four_run/test.js +0 -7
- package/convert/multiply_divide/index.js +0 -197
- package/convert/multiply_divide/test.js +0 -14
- package/convert/plus_subtract/index.js +0 -160
- package/convert/plus_subtract/test.js +0 -15
- package/convert/readme.md +0 -2
- package/doc/mm_math.doc +0 -0
- 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
- package/express/README.md +0 -2
- package/identities/chemistry/readme.md +0 -1
- package/identities/equation/readme.md +0 -2
- package/identities/geometry/readme.md +0 -1
- package/identities/geometry/rectangle/readme.md +0 -1
- package/identities/geometry/string/readme.md +0 -1
- package/identities/physics/readme.md +0 -1
- package/identities/readme.md +0 -2
- package/math/array/average/index.js +0 -10
- package/math/array/average/math.json +0 -8
- package/math/array/average/test.js +0 -3
- package/math/array/col/index.js +0 -17
- package/math/array/col/math.json +0 -8
- package/math/array/col/test.js +0 -4
- package/math/array/composite/index.js +0 -35
- package/math/array/composite/math.json +0 -8
- package/math/array/composite/test.js +0 -4
- package/math/array/deviations/index.js +0 -15
- package/math/array/deviations/math.json +0 -8
- package/math/array/deviations/test.js +0 -3
- package/math/array/difference/index.js +0 -9
- package/math/array/difference/math.json +0 -8
- package/math/array/difference/test.js +0 -7
- package/math/array/distinct/index.js +0 -20
- package/math/array/distinct/math.json +0 -8
- package/math/array/distinct/test.js +0 -8
- package/math/array/distributive/index.js +0 -24
- package/math/array/distributive/math.json +0 -8
- package/math/array/distributive/test.js +0 -3
- package/math/array/divisor/index.js +0 -17
- package/math/array/divisor/math.json +0 -8
- package/math/array/divisor/test.js +0 -6
- package/math/array/intersect/index.js +0 -9
- package/math/array/intersect/math.json +0 -8
- package/math/array/intersect/test.js +0 -7
- package/math/array/max/index.js +0 -17
- package/math/array/max/math.json +0 -8
- package/math/array/max/test.js +0 -8
- package/math/array/median/index.js +0 -34
- package/math/array/median/math.json +0 -8
- package/math/array/median/test.js +0 -4
- package/math/array/min/index.js +0 -16
- package/math/array/min/math.json +0 -8
- package/math/array/min/test.js +0 -8
- package/math/array/multiple/index.js +0 -17
- package/math/array/multiple/math.json +0 -8
- package/math/array/multiple/test.js +0 -7
- package/math/array/natural/index.js +0 -17
- package/math/array/natural/math.json +0 -8
- package/math/array/natural/test.js +0 -9
- package/math/array/pos/index.js +0 -21
- package/math/array/pos/math.json +0 -8
- package/math/array/pos/test.js +0 -41
- package/math/array/prime/index.js +0 -35
- package/math/array/prime/math.json +0 -8
- package/math/array/prime/test.js +0 -4
- package/math/array/readme.md +0 -5
- package/math/array/reduction/index.js +0 -57
- package/math/array/reduction/math.json +0 -8
- package/math/array/reduction/test.js +0 -42
- package/math/array/rising/index.js +0 -8
- package/math/array/rising/math.json +0 -8
- package/math/array/rising/test.js +0 -3
- package/math/array/row/index.js +0 -11
- package/math/array/row/math.json +0 -8
- package/math/array/row/test.js +0 -4
- package/math/array/square/index.js +0 -12
- package/math/array/square/math.json +0 -8
- package/math/array/square/test.js +0 -3
- package/math/array/stddev/index.js +0 -17
- package/math/array/stddev/math.json +0 -8
- package/math/array/stddev/test.js +0 -4
- package/math/array/sum/index.js +0 -13
- package/math/array/sum/math.json +0 -8
- package/math/array/sum/test.js +0 -3
- package/math/array/sumproduct/index.js +0 -13
- package/math/array/sumproduct/math.json +0 -8
- package/math/array/sumproduct/test.js +0 -3
- package/math/array/union/index.js +0 -11
- package/math/array/union/math.json +0 -8
- package/math/array/union/test.js +0 -7
- package/math/base/abs/index.js +0 -8
- package/math/base/abs/math.json +0 -8
- package/math/base/abs/test.js +0 -3
- package/math/base/ceil/index.js +0 -8
- package/math/base/ceil/math.json +0 -8
- package/math/base/ceil/test.js +0 -3
- package/math/base/denominator/index.js +0 -17
- package/math/base/denominator/math.json +0 -9
- package/math/base/denominator/test.js +0 -3
- package/math/base/diff/index.js +0 -9
- package/math/base/diff/math.json +0 -8
- package/math/base/diff/test.js +0 -6
- package/math/base/exp/index.js +0 -8
- package/math/base/exp/math.json +0 -8
- package/math/base/exp/test.js +0 -6
- package/math/base/floor/index.js +0 -8
- package/math/base/floor/math.json +0 -8
- package/math/base/floor/test.js +0 -3
- package/math/base/int/index.js +0 -8
- package/math/base/int/math.json +0 -8
- package/math/base/int/test.js +0 -2
- package/math/base/log/index.js +0 -8
- package/math/base/log/math.json +0 -8
- package/math/base/log/test.js +0 -4
- package/math/base/max_divisor/index.js +0 -10
- package/math/base/max_divisor/math.json +0 -9
- package/math/base/max_divisor/test.js +0 -3
- package/math/base/min_multiple/index.js +0 -11
- package/math/base/min_multiple/math.json +0 -9
- package/math/base/min_multiple/test.js +0 -3
- package/math/base/mod/index.js +0 -8
- package/math/base/mod/math.json +0 -8
- package/math/base/mod/test.js +0 -3
- package/math/base/pow/index.js +0 -9
- package/math/base/pow/math.json +0 -8
- package/math/base/pow/test.js +0 -3
- package/math/base/rand/index.js +0 -21
- package/math/base/rand/math.json +0 -8
- package/math/base/rand/test.js +0 -3
- package/math/base/random/index.js +0 -12
- package/math/base/random/math.json +0 -8
- package/math/base/random/test.js +0 -4
- package/math/base/readme.md +0 -1
- package/math/base/round/index.js +0 -14
- package/math/base/round/math.json +0 -8
- package/math/base/round/test.js +0 -4
- package/math/base/sqrt/index.js +0 -8
- package/math/base/sqrt/math.json +0 -8
- package/math/base/sqrt/test.js +0 -5
- package/math/readme.md +0 -1
- package/math/stock/AMOUNT/index.js +0 -7
- package/math/stock/AMOUNT/math.json +0 -8
- package/math/stock/AMOUNT/test.js +0 -4
- package/math/stock/AP/index.js +0 -20
- package/math/stock/AP/math.json +0 -8
- package/math/stock/AP/test.js +0 -5
- package/math/stock/AROON/index.js +0 -14
- package/math/stock/ARR/index.js +0 -10
- package/math/stock/ARR/math.json +0 -8
- package/math/stock/ARR/test.js +0 -45
- package/math/stock/ASTAR/index.js +0 -20
- package/math/stock/ASTAR/math.json +0 -8
- package/math/stock/ASTAR/test.js +0 -4
- package/math/stock/AVERAGE/index.js +0 -14
- package/math/stock/AVERAGE/math.json +0 -8
- package/math/stock/AVERAGE/test.js +0 -5
- package/math/stock/AYANG/index.js +0 -18
- package/math/stock/AYANG/math.json +0 -8
- package/math/stock/AYANG/test.js +0 -4
- package/math/stock/AYIN/index.js +0 -18
- package/math/stock/AYIN/math.json +0 -8
- package/math/stock/AYIN/test.js +0 -4
- package/math/stock/BBANDS/index.js +0 -0
- package/math/stock/BETWEEN/index.js +0 -24
- package/math/stock/BETWEEN/math.json +0 -8
- package/math/stock/BETWEEN/test.js +0 -4
- package/math/stock/CLOSE/c.js +0 -0
- package/math/stock/CLOSE/index.js +0 -11
- package/math/stock/CLOSE/math.json +0 -8
- package/math/stock/CLOSE/test.js +0 -45
- package/math/stock/CP/index.js +0 -35
- package/math/stock/CP/math.json +0 -8
- package/math/stock/CP/test.js +0 -5
- package/math/stock/CROSS/index.js +0 -29
- package/math/stock/CROSS/math.json +0 -8
- package/math/stock/CROSS/test.js +0 -6
- package/math/stock/DATE/index.js +0 -14
- package/math/stock/DATE/math.json +0 -8
- package/math/stock/DATE/test.js +0 -45
- package/math/stock/DOWN/index.js +0 -19
- package/math/stock/DOWN/math.json +0 -8
- package/math/stock/DOWN/test.js +0 -8
- package/math/stock/DOWNNDAY/index.js +0 -27
- package/math/stock/DOWNNDAY/math.json +0 -8
- package/math/stock/DOWNNDAY/test.js +0 -10
- package/math/stock/EMA/index.js +0 -30
- package/math/stock/EMA/math.json +0 -8
- package/math/stock/EMA/test.js +0 -4
- package/math/stock/HHV/index.js +0 -16
- package/math/stock/HHV/math.json +0 -8
- package/math/stock/HHV/test.js +0 -4
- package/math/stock/HIGH/h.js +0 -0
- package/math/stock/HIGH/index.js +0 -11
- package/math/stock/HIGH/math.json +0 -8
- package/math/stock/HIGH/test.js +0 -45
- package/math/stock/LEFT/index.js +0 -13
- package/math/stock/LEFT/math.json +0 -8
- package/math/stock/LEFT/test.js +0 -4
- package/math/stock/LLV/index.js +0 -16
- package/math/stock/LLV/math.json +0 -8
- package/math/stock/LLV/test.js +0 -4
- package/math/stock/LOW/index.js +0 -11
- package/math/stock/LOW/l.js +0 -0
- package/math/stock/LOW/math.json +0 -8
- package/math/stock/LOW/test.js +0 -47
- package/math/stock/MA/index.js +0 -30
- package/math/stock/MA/math.json +0 -8
- package/math/stock/MA/test.js +0 -5
- package/math/stock/MACD/index.js +0 -29
- package/math/stock/MACD/math.json +0 -8
- package/math/stock/MACD/test.js +0 -4
- package/math/stock/MFI/index.js +0 -33
- package/math/stock/NMA/index.js +0 -23
- package/math/stock/NMA/math.json +0 -8
- package/math/stock/NMA/test.js +0 -5
- package/math/stock/NOT/index.js +0 -7
- package/math/stock/NOT/math.json +0 -8
- package/math/stock/NOT/test.js +0 -10
- package/math/stock/OPEN/index.js +0 -11
- package/math/stock/OPEN/math.json +0 -8
- package/math/stock/OPEN/o.js +0 -0
- package/math/stock/OPEN/test.js +0 -45
- package/math/stock/PERCPRICEOSC/index.js +0 -19
- package/math/stock/REF/index.js +0 -15
- package/math/stock/REF/math.json +0 -8
- package/math/stock/REF/test.js +0 -5
- package/math/stock/RIGHT/index.js +0 -13
- package/math/stock/RIGHT/math.json +0 -8
- package/math/stock/RIGHT/test.js +0 -4
- package/math/stock/RSI/index.js +0 -36
- package/math/stock/SMA/index.js +0 -12
- package/math/stock/STAR/index.js +0 -19
- package/math/stock/STAR/math.json +0 -8
- package/math/stock/STAR/test.js +0 -4
- package/math/stock/STOCHRSI/index.js +0 -19
- package/math/stock/SUM/index.js +0 -19
- package/math/stock/SUM/math.json +0 -8
- package/math/stock/SUM/test.js +0 -7
- package/math/stock/TIME/index.js +0 -14
- package/math/stock/TIME/math.json +0 -8
- package/math/stock/TIME/test.js +0 -45
- package/math/stock/TRUERANGE/index.js +0 -19
- package/math/stock/UP/index.js +0 -19
- package/math/stock/UP/math.json +0 -8
- package/math/stock/UP/test.js +0 -9
- package/math/stock/UPNDAY/index.js +0 -28
- package/math/stock/UPNDAY/math.json +0 -8
- package/math/stock/UPNDAY/test.js +0 -10
- package/math/stock/VMA/index.js +0 -41
- package/math/stock/VMA/math.json +0 -8
- package/math/stock/VMA/test.js +0 -7
- package/math/stock/VOL/index.js +0 -11
- package/math/stock/VOL/math.json +0 -8
- package/math/stock/VOL/test.js +0 -45
- package/math/stock/WILLR/index.js +0 -22
- package/math/stock/YANG/index.js +0 -16
- package/math/stock/YANG/math.json +0 -8
- package/math/stock/YANG/test.js +0 -4
- package/math/stock/YIN/index.js +0 -16
- package/math/stock/YIN/math.json +0 -8
- package/math/stock/YIN/test.js +0 -4
- package/math/stock/readme.md +0 -294
- package/math/trigonometric/cos/index.js +0 -8
- package/math/trigonometric/cos/math.json +0 -20
- package/math/trigonometric/cot/index.js +0 -8
- package/math/trigonometric/cot/math.json +0 -17
- package/math/trigonometric/csc/index.js +0 -8
- package/math/trigonometric/csc/math.json +0 -20
- package/math/trigonometric/readme.md +0 -2
- package/math/trigonometric/sec/index.js +0 -8
- package/math/trigonometric/sec/math.json +0 -20
- package/math/trigonometric/sin/index.js +0 -8
- package/math/trigonometric/sin/math.json +0 -20
- package/math/trigonometric/tan/index.js +0 -8
- package/math/trigonometric/tan/math.json +0 -18
- package/symbol/brackets/index.js +0 -46
- package/symbol/brackets/symbol.json +0 -8
- package/symbol/brackets/test.js +0 -12
- package/symbol/decimal/index.js +0 -41
- package/symbol/decimal/symbol.json +0 -8
- package/symbol/decimal/test.js +0 -2
- package/symbol/percentage/index.js +0 -48
- package/symbol/percentage/symbol.json +0 -8
- package/symbol/percentage/test.js +0 -2
- package/symbol/pi/index.js +0 -20
- package/symbol/pi/symbol.json +0 -9
- package/symbol/pi/test.js +0 -2
- package/symbol/power/index.js +0 -111
- package/symbol/power/symbol.json +0 -8
- package/symbol/power/test.js +0 -10
- package/symbol/readme.md +0 -2
- package/test.js +0 -32
- package/test2.js +0 -47
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 去除重复
|
|
3
|
-
* @param {Array} arr
|
|
4
|
-
* @return {Number} 返回最小值
|
|
5
|
-
*/
|
|
6
|
-
module.exports = function distinct(arr) {
|
|
7
|
-
var i = 0;
|
|
8
|
-
var j = 0;
|
|
9
|
-
var len = arr.length;
|
|
10
|
-
for (i = 0; i < len; i++) {
|
|
11
|
-
for (j = i + 1; j < len; j++) {
|
|
12
|
-
if (arr[i] == arr[j]) {
|
|
13
|
-
arr.splice(j, 1);
|
|
14
|
-
len--;
|
|
15
|
-
j--;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return arr;
|
|
20
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 分配
|
|
3
|
-
* @param {Array} arr_1 数组1
|
|
4
|
-
* @param {Array} arr_2 数组2
|
|
5
|
-
* @param {string} mode 方法
|
|
6
|
-
* @return {Number} 返回最小值
|
|
7
|
-
*/
|
|
8
|
-
module.exports = function distributive(arr_1, arr_2, mode) {
|
|
9
|
-
if(mode === '+'){
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
else if(mode === '-'){
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
else if(mode === '/'){
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
else if(mode === '*'){
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
else if(mode === '%'){
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const min = require('../min');
|
|
2
|
-
const max_divisor = require('../../base/max_divisor');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 取最大公因数
|
|
6
|
-
* @param {Array} arr
|
|
7
|
-
* @return {Number} 返回最大公因数
|
|
8
|
-
*/
|
|
9
|
-
module.exports = function multiple(arr) {
|
|
10
|
-
// 获取最小值
|
|
11
|
-
var m = min(arr);
|
|
12
|
-
var len = arr.length;
|
|
13
|
-
for (var i = 0; i < len; i++) {
|
|
14
|
-
m = max_divisor(m, arr[i]);
|
|
15
|
-
}
|
|
16
|
-
return m;
|
|
17
|
-
};
|
package/math/array/max/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 取最大值
|
|
3
|
-
* @param {Array} arr
|
|
4
|
-
* @return {Number} 返回最大值
|
|
5
|
-
*/
|
|
6
|
-
module.exports = function max(arr) {
|
|
7
|
-
var number = 0;
|
|
8
|
-
var len = arr.length;
|
|
9
|
-
for (var i = 0; i < len; i++) {
|
|
10
|
-
var num = arr[i];
|
|
11
|
-
if(num > number)
|
|
12
|
-
{
|
|
13
|
-
number = num;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return number;
|
|
17
|
-
};
|
package/math/array/max/math.json
DELETED
package/math/array/max/test.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 取中位数
|
|
3
|
-
* @param {Array} arr 数组
|
|
4
|
-
* @return {Number} 返回中位数
|
|
5
|
-
*/
|
|
6
|
-
module.exports = function median(arr) {
|
|
7
|
-
// 先排序
|
|
8
|
-
var ar = arr;
|
|
9
|
-
ar.sort(function(x, y) {
|
|
10
|
-
if (x < y) {
|
|
11
|
-
return -1;
|
|
12
|
-
} else if (x > y) {
|
|
13
|
-
return 1;
|
|
14
|
-
} else {
|
|
15
|
-
return 0;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var len = ar.length;
|
|
19
|
-
|
|
20
|
-
var index = len / 2;
|
|
21
|
-
var mid;
|
|
22
|
-
|
|
23
|
-
// 判断数值个数是否能被2整除, 如果能则取中间两个数的平均值
|
|
24
|
-
if (index === parseInt(index)) {
|
|
25
|
-
var left = ar[index - 1];
|
|
26
|
-
var right = ar[index];
|
|
27
|
-
mid = (left + right) / 2
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
// 如果数值个数不能被2整除, 则直接取中间值
|
|
31
|
-
mid = ar[Math.ceil(index) - 1]
|
|
32
|
-
}
|
|
33
|
-
return mid;
|
|
34
|
-
};
|
package/math/array/min/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 取最小值
|
|
3
|
-
* @param {Array} arr
|
|
4
|
-
* @return {Number} 返回最小值
|
|
5
|
-
*/
|
|
6
|
-
module.exports = function max(arr) {
|
|
7
|
-
var number = arr[0];
|
|
8
|
-
for (var i = 1; i < arr.length; i++) {
|
|
9
|
-
var num = arr[i];
|
|
10
|
-
if(num < number)
|
|
11
|
-
{
|
|
12
|
-
number = num;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return number;
|
|
16
|
-
};
|
package/math/array/min/math.json
DELETED
package/math/array/min/test.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const sumproduct = require('../sumproduct');
|
|
2
|
-
const max = require('../max');
|
|
3
|
-
const min_multiple = require('../../base/min_multiple');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 取最小公倍数
|
|
7
|
-
* @param {Array} arr
|
|
8
|
-
* @return {Number} 返回取最小公倍数
|
|
9
|
-
*/
|
|
10
|
-
module.exports = function multiple(arr) {
|
|
11
|
-
var n = max(arr);
|
|
12
|
-
var len = arr.length;
|
|
13
|
-
for (var i = 0; i < len; i++) {
|
|
14
|
-
n = min_multiple(n, arr[i]);
|
|
15
|
-
}
|
|
16
|
-
return n;
|
|
17
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const multiple = require('./index');
|
|
2
|
-
console.log(multiple([4, 20, 16, 8]));
|
|
3
|
-
console.log(multiple([4, 14, 16, 8]));
|
|
4
|
-
console.log(multiple([14, 20, 16, 8]));
|
|
5
|
-
console.log(multiple([66, 121, 22, 33]));
|
|
6
|
-
console.log(multiple([66, 33, 22]));
|
|
7
|
-
console.log(multiple([2, 3, 5, 7]));
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 取自然数
|
|
3
|
-
* @param {Array} arr
|
|
4
|
-
* @return {Array} 返回自然数数组
|
|
5
|
-
*/
|
|
6
|
-
module.exports = function natural(arr) {
|
|
7
|
-
var arr_new = [];
|
|
8
|
-
var len = arr.length;
|
|
9
|
-
for (var i = 0; i < len; i++) {
|
|
10
|
-
var num = arr[i];
|
|
11
|
-
if(num >= 0 && num === parseInt(num))
|
|
12
|
-
{
|
|
13
|
-
arr_new.push(num);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return arr_new;
|
|
17
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const natural = require('./index');
|
|
2
|
-
const max = require('./index');
|
|
3
|
-
var arr = [15, 35, -68, 6.6, 0];
|
|
4
|
-
var arr_2 = [38, 3.1415926, 68];
|
|
5
|
-
var arr_3 = [25, 35, -22, -0.33];
|
|
6
|
-
|
|
7
|
-
console.log(natural(arr));
|
|
8
|
-
console.log(natural(arr_2));
|
|
9
|
-
console.log(natural(arr_3));
|
package/math/array/pos/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 维度取值X,Y,Z
|
|
3
|
-
* @param {Array} arr
|
|
4
|
-
* @param {Number} x 一维
|
|
5
|
-
* @param {Number} y 二维
|
|
6
|
-
* @param {Number} z 三维
|
|
7
|
-
* @return {Number|Array} 返回数组或数值
|
|
8
|
-
*/
|
|
9
|
-
module.exports = function pos(arr, x, y, z) {
|
|
10
|
-
var ar = arr;
|
|
11
|
-
if (ar.length >= x) {
|
|
12
|
-
ar = ar[x - 1];
|
|
13
|
-
if (y && ar.length >= y) {
|
|
14
|
-
ar = ar[y - 1];
|
|
15
|
-
if (z && ar.length >= z) {
|
|
16
|
-
ar = ar[z - 1];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return ar;
|
|
21
|
-
};
|
package/math/array/pos/math.json
DELETED
package/math/array/pos/test.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const pos = require('./index');
|
|
2
|
-
var arr = [
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[1, 2, 3],
|
|
6
|
-
[4, 5, 6],
|
|
7
|
-
[7, 8, 9],
|
|
8
|
-
],
|
|
9
|
-
[
|
|
10
|
-
[2, 3, 4],
|
|
11
|
-
[5, 6, 7],
|
|
12
|
-
[8, 9, 10],
|
|
13
|
-
]
|
|
14
|
-
],
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[2, 3, 4],
|
|
18
|
-
[4, 6, 8],
|
|
19
|
-
[8, 9, 12]
|
|
20
|
-
],
|
|
21
|
-
[
|
|
22
|
-
[3, 4, 5],
|
|
23
|
-
[6, 8, 10],
|
|
24
|
-
[9, 12, 15]
|
|
25
|
-
]
|
|
26
|
-
],
|
|
27
|
-
[
|
|
28
|
-
[
|
|
29
|
-
[3, 4, 5],
|
|
30
|
-
[6, 8, 10],
|
|
31
|
-
[9, 12, 15]
|
|
32
|
-
],
|
|
33
|
-
[
|
|
34
|
-
[9, 12, 15],
|
|
35
|
-
[6, 8, 10],
|
|
36
|
-
[3, 4, 5]
|
|
37
|
-
]
|
|
38
|
-
]
|
|
39
|
-
];
|
|
40
|
-
console.log(pos(arr, 2, 2, 1));
|
|
41
|
-
console.log(pos(arr, 1, 2, 3));
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
function isPrinme(n) {
|
|
2
|
-
if (n == 0 || n == 1) {
|
|
3
|
-
return false;
|
|
4
|
-
}
|
|
5
|
-
if (n == 2) {
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
var times = Math.sqrt(n);
|
|
9
|
-
if (times == parseInt(times)) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
for (var i = 2; i < times; i++) {
|
|
13
|
-
if (n % i == 0) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 取所有素数
|
|
22
|
-
* @param {Array} arr 数组
|
|
23
|
-
* @return {Array} 返回素数集合
|
|
24
|
-
*/
|
|
25
|
-
module.exports = function prime(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 (isPrinme(n)) {
|
|
31
|
-
arr_new.push(n);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return arr_new;
|
|
35
|
-
};
|
package/math/array/prime/test.js
DELETED
package/math/array/readme.md
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 维度下降(基础)
|
|
3
|
-
* @param {Array} arr 数组
|
|
4
|
-
* @param {Number} n 下降次数
|
|
5
|
-
* @return {Array} 返回下降后的数组
|
|
6
|
-
*/
|
|
7
|
-
function flatten(arr) {
|
|
8
|
-
var arr_new = [];
|
|
9
|
-
var len = arr.length;
|
|
10
|
-
for (var i = 0; i < len; i++) {
|
|
11
|
-
var val = arr[i];
|
|
12
|
-
if (Array.isArray(val)) {
|
|
13
|
-
var ar = flatten(val);
|
|
14
|
-
ar.map(function(o) {
|
|
15
|
-
arr_new.push(o);
|
|
16
|
-
});
|
|
17
|
-
} else {
|
|
18
|
-
arr_new.push(val);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return arr_new;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// var r = [
|
|
25
|
-
// [2, 3, 1, 3, [4, 5],
|
|
26
|
-
// [5, 9, 10], 8
|
|
27
|
-
// ],
|
|
28
|
-
// [4, 7, 7, 6]
|
|
29
|
-
// ];
|
|
30
|
-
// console.log(flatten(r));
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 维度下降
|
|
34
|
-
* @param {Array} arr 数组
|
|
35
|
-
* @param {Number} n 下降次数
|
|
36
|
-
* @return {Array} 返回下降后的数组
|
|
37
|
-
*/
|
|
38
|
-
module.exports = function reduction(arr, n) {
|
|
39
|
-
if (n) {
|
|
40
|
-
var depth = 0;
|
|
41
|
-
var ar = arr;
|
|
42
|
-
while (Array.isArray(ar) && ar.length > 0) {
|
|
43
|
-
ar = ar[0];
|
|
44
|
-
depth++;
|
|
45
|
-
}
|
|
46
|
-
var arr_new = [];
|
|
47
|
-
// 循环次数
|
|
48
|
-
var times = depth - n;
|
|
49
|
-
|
|
50
|
-
if (times < 1) {
|
|
51
|
-
times = 1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
return flatten(arr)
|
|
56
|
-
}
|
|
57
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const reduction = require('./index');
|
|
2
|
-
var arr = [
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[1, 2, 3],
|
|
6
|
-
[4, 5, 6],
|
|
7
|
-
[7, 8, 9],
|
|
8
|
-
],
|
|
9
|
-
[
|
|
10
|
-
[2, 3, 4],
|
|
11
|
-
[5, 6, 7],
|
|
12
|
-
[8, 9, 10],
|
|
13
|
-
]
|
|
14
|
-
],
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[2, 3, 4],
|
|
18
|
-
[4, 6, 8],
|
|
19
|
-
[8, 9, 12]
|
|
20
|
-
],
|
|
21
|
-
[
|
|
22
|
-
[3, 4, 5],
|
|
23
|
-
[6, 8, 10],
|
|
24
|
-
[9, 12, 15]
|
|
25
|
-
]
|
|
26
|
-
],
|
|
27
|
-
[
|
|
28
|
-
[
|
|
29
|
-
[3, 4, 5],
|
|
30
|
-
[6, 8, 10],
|
|
31
|
-
[9, 12, 15]
|
|
32
|
-
],
|
|
33
|
-
[
|
|
34
|
-
[9, 12, 15],
|
|
35
|
-
[6, 8, 10],
|
|
36
|
-
[3, 4, 5]
|
|
37
|
-
]
|
|
38
|
-
]
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
console.log(reduction(arr, 2));
|
|
42
|
-
console.log(reduction(arr, 1));
|
package/math/array/row/index.js
DELETED
package/math/array/row/math.json
DELETED
package/math/array/row/test.js
DELETED