-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_functions_helpers.js~
55 lines (50 loc) · 1.23 KB
/
user_functions_helpers.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Computes the number of leaf ideas (concepts) below the node
*/
function compute_concepts_below (node) {
var count = 0;
node.eachSubgraph(
function(n){
if (n.getSubnodes(1).length == 0) {count++;}
}
)
return count;
}
/*
* Returns true is the node is a leaf node (no children) else returns true
*
*/
function isLeafNode(node) {
// console.log(node);
return (node.getSubnodes(1).length == 0) ? true : false;
}
/*
* Calculates the log of my_value with user-defined base my_base
*
*/
function math_log_base(my_value, my_base) {
return Math.log(my_value)/Math.log(my_base)
}
/*
* Add the sum function to the Array object
*
*/
Array.prototype.sum = function() {
for (var i = 0, L = this.length, sum = 0; i < L; sum += this[i++]);
return sum;
}
/*
* Add the log function to the Array object
*
*/
Array.prototype.logarithm = function(my_base) {
for (var i = 0, L = this.length, arr_log = new Array(L); i < L; i++) {arr_log[i] = math_log_base(this[i], my_base)};
return arr_log;
}
/*
* Add the log function to the Array object
*
*/
Array.prototype.max = function(){
return Math.max.apply( Math, this );
}