Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

20
LINES

< > BotCompany Repo | #1036342 // BestWorstAndAverage - collect average score, worst element, best element

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10049L/55K).

sclass BestWorstAndAverage<A> {
  IBest<A> best = new Best;
  IBest<A> worst = new Lowest;
  new Average average;
  
  selfType lowerIsBetter() {
    best = new Lowest;
    worst = new Best;
    this;
  }

  bool put(A a, double score) {
    average.add(score);
    ret best.put(a, score) | worst.put(a, score);
  }
  
  toString {
    ret renderVars(avg := average, +best, +worst);
  }
}

Author comment

Began life as a copy of #1034575

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036342
Snippet name: BestWorstAndAverage - collect average score, worst element, best element
Eternal ID of this version: #1036342/5
Text MD5: aa72e44b6ad93a5dbd5c16308a3a8bda
Transpilation MD5: 69a5af253d29ce4d8044524fd6fba9fd
Author: stefan
Category: javax / maths
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-11-21 11:30:43
Source code size: 407 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 126 / 193
Version history: 4 change(s)
Referenced in: [show references]