-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrCom.js
39 lines (35 loc) · 977 Bytes
/
arrCom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const math = require("./math");
Array.prototype.peek = function() {
return this[this.length - 1];
};
module.exports.NumberMerge = arr => {
let newArr = [];
arr.forEach(x => {
if (math.IsNumber(x) || x == ".") {
if (newArr.length > 0 && math.IsNumber(newArr[newArr.length - 1]))
newArr[newArr.length - 1] += x;
else newArr.push(x);
} else {
newArr.push(x);
}
});
return newArr;
};
module.exports.StackInt = arr => {
let newArr = arr.map(x => {
if (math.IsNumber(x)) {
return parseInt(x);
} else return x;
});
return newArr;
};
module.exports.IsDelimeter = get => {
if (["=", " "].indexOf(get) != -1) return true;
return false;
};
module.exports.IsDubling = get => {
return get.filter((item, pos, arr) => !pos || item !== arr[pos - 1]);
};
module.exports.ClaerExpr = get => {
return get.split("").filter(e => e != " ");
};