RunTimeArray.js 911 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. class RunTimeArray {
  2. constructor() {
  3. E(this, "circularData");
  4. this.circularData = []
  5. }
  6. add(e) {
  7. this.circularData.length > 1e3 && this.circularData.shift(),
  8. this.circularData.push(e)
  9. }
  10. getAvg() {
  11. let e = 0;
  12. for (let t = 0; t < this.circularData.length; t++)
  13. e += this.circularData[t];
  14. return {
  15. sum: e,
  16. avg: e / this.circularData.length || 0
  17. }
  18. }
  19. getMax() {
  20. let e = 0;
  21. for (let t = 0; t < this.circularData.length; t++)
  22. e < this.circularData[t] && (e = this.circularData[t]);
  23. return e || 0
  24. }
  25. clear() {
  26. this.circularData = []
  27. }
  28. getStat() {
  29. const e = this.getAvg()
  30. , t = {
  31. sum: e.sum,
  32. avg: e.avg,
  33. max: this.getMax()
  34. };
  35. return this.clear(),
  36. t
  37. }
  38. }