actionscript 3 - Getting delta of array values from constantly updating array -
having problem getting should rather simple work. updating array new values , need delta or difference between lowest , highest values. length of array should remain constant @ 10. problem 1st , lastly values of delta array seem change. missing?
although in as3, should identical in java or javascript
private var _deltaarray:array= new array(); private function update(myval:int):void{ if (_deltaarray.length < 10) { _deltaarray.push(myval); } if (_deltaarray.length >= 10) { _deltaarray.push(myval); var delta:int =getdelta(_deltaarray); _deltaarray.shift(); } }//end func private function getdelta(a:array):int { var total:number=0; var l:int=a.length if (l > 1) { a.sort(array.numeric); var delta:int=int(a[0]) - int(a[l - 1]); trace('getdelta delta= ' + delta); } homecoming delta; }//end func
this suggestion, why not maintain running count of delta? can code in pseudo-code, but:
private double max = double.min; private double min = double.max; private void update(integer value) { array.push(value); max = value > max ? value : max; min = value < min ? value : min; if (array.length > 10) { array.shift(); } } private int delta() { homecoming max - min; }
arrays actionscript-3 ecmascript-5
No comments:
Post a Comment