slitaz-dev-tools rev 238 2.2
tazwikiss: add min, max, cnt
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Feb 22 11:10:22 2015 +0100 (2015-02-22) |
parents | 674bad1f758b |
children | dbf9d98daf67 |
files | tazwikiss/rootfs/var/www/wiki/plugins/wkp_Calc.sh |
line diff
1.1 --- a/tazwikiss/rootfs/var/www/wiki/plugins/wkp_Calc.sh Sat Feb 21 13:58:12 2015 +0100 1.2 +++ b/tazwikiss/rootfs/var/www/wiki/plugins/wkp_Calc.sh Sun Feb 22 11:10:22 2015 +0100 1.3 @@ -21,19 +21,25 @@ 1.4 alert(data); 1.5 } 1.6 1.7 -var DATA={}; 1.8 -function sum(id,from,to) { 1.9 - var result=0 1.10 +function cnt(from,to) { 1.11 + return (to.charCodeAt(0) - from.charCodeAt(0) + 1) * 1.12 + (parseInt(to.substring(1)) - parseInt(from.substring(1)) + 1) 1.13 +} 1.14 + 1.15 +function zone(id,from,to,init,func) { 1.16 + var result=init 1.17 for (var l=from.charCodeAt(0);;l++) { 1.18 for (var n=parseInt(from.substring(1)); 1.19 n <= parseInt(to.substring(1));n++) { 1.20 var e=document.getElementById(id+String.fromCharCode(l)+n) 1.21 - result+=parseFloat(e.value) 1.22 + result=func(result,parseFloat(e.value)) 1.23 } 1.24 if (l == to.charCodeAt(0)) break 1.25 } 1.26 return result; 1.27 } 1.28 + 1.29 +var DATA={}; 1.30 function buildCalc(id, rows, cols) { 1.31 DATA[id] = {}; 1.32 var maths = [ "abs", "acos", "asin", "atan", "atan2", "ceil", "cos", "exp", 1.33 @@ -49,7 +55,13 @@ 1.34 function(n){var x=1;while(n>1)x*=n--;return x;}; 1.35 DATA[id].fib = DATA[id].FIB = 1.36 function(n){var c=0,p=1;while(n-->0){var x=c;c+=p;p=x};return c;}; 1.37 - DATA[id].sum = DATA[id].SUM = function(a,b){return sum(id,a,b);}; 1.38 + DATA[id].sum = DATA[id].SUM = 1.39 + function(a,b){return zone(id,a,b,0,function(a,b){return a+b});}; 1.40 + DATA[id].min = DATA[id].MIN = 1.41 + function(a,b){return zone(id,a,b,Number.MAX_VALUE,Math.min);}; 1.42 + DATA[id].max = DATA[id].MAX = 1.43 + function(a,b){return zone(id,a,b,Number.MIN_VALUE,Math.max);}; 1.44 + DATA[id].cnt = DATA[id].CNT = cnt 1.45 for (var i=0; i<=rows; i++) { 1.46 var row = document.getElementById(id).insertRow(-1); 1.47 for (var j=0; j<=cols && j<=26; j++) {