-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerm.js
More file actions
35 lines (33 loc) · 779 Bytes
/
Term.js
File metadata and controls
35 lines (33 loc) · 779 Bytes
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
function Term(coeff, terms, power) {
return {
coeff: coeff,
terms: terms,
power: power,
diff: function(withRespectTo) {
let wrt = terms.indexOf(withRespectTo);
if (wrt === -1) {
coeff = 0;
} else {
coeff *= power[wrt]--;
}
},
multiply: function(term) {
coeff *= term.coeff;
// check the existence of each term in the local term with the foreign one
},
print: function() {
let answer = coeff.toString();
if (coeff !== 0) {
for (let i = 0; i < terms.length; i++) {
if (power[i] !== 0) {
answer += terms[i];
}
if (power[i] > 1) {
answer += power[i];
}
}
}
return answer;
}
};
}