The average monoid in javascript