-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionManipulations.js
More file actions
65 lines (52 loc) · 1.41 KB
/
Copy pathfunctionManipulations.js
File metadata and controls
65 lines (52 loc) · 1.41 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
export function inputToValidMath(input, x) {
input = input.replace(/(PI|pi)/g, 'Math.PI')
input = multiplications(input)
//input = input.replaceAll('-x', `(${-x})`)
//input = input.replaceAll('x', `(${x})`)
input = everything(input)
return input
}
function everything(input) {
input = pow(input)
input = sqrt(input)
input = sin(input)
input = cos(input)
input = tan(input)
input = abs(input)
return input
}
function multiplications(input) {
if (input.startsWith('-x')) input = input.replace('-x', '-1x')
const multiplications = input.match(/-?[\d.e]+x/g)
if (multiplications)
multiplications.forEach((multiplication) => {
const number = multiplication.match(/[\d-.e]+/)[0]
input = input.replace(multiplication, `${number}*x`)
})
return input
}
function sqrt(input) {
input = input.replaceAll('sqrt', 'Math.sqrt')
return input
}
function sin(input) {
input = input.replaceAll('sin', 'Math.sin')
return input
}
function cos(input) {
input = input.replaceAll('cos', 'Math.cos')
return input
}
function tan(input) {
input = input.replaceAll('tan', 'Math.tan')
return input
}
function pow(input) {
input = input.replaceAll('pow', 'Math.pow')
input = input.replaceAll('^', '**')
return input
}
function abs(input) {
input = input.replaceAll('abs', 'Math.abs')
return input
}