Sha256: dcdb5184781c40743b9ee84c56693a71487af6bf9459c963be558b0b389d08e1

Contents?: true

Size: 424 Bytes

Versions: 6

Compression:

Stored size: 424 Bytes

Contents

require_relative '../function'

Dentaku::AST::Function.register(:avg, :numeric, ->(*args) {
  flatten_args = args.flatten
  if flatten_args.empty?
    raise Dentaku::ArgumentError.for(
        :too_few_arguments,
        function_name: 'AVG()', at_least: 1, given: 0
    ), 'AVG() requires at least one argument'
  end

  flatten_args.map { |arg| Dentaku::AST::Function.numeric(arg) }.reduce(0, :+) / flatten_args.length
})

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
dentaku_zevo-3.5.2 lib/dentaku/ast/functions/avg.rb
dentaku-3.5.1 lib/dentaku/ast/functions/avg.rb
dentaku-3.5.0 lib/dentaku/ast/functions/avg.rb
dentaku-3.4.2 lib/dentaku/ast/functions/avg.rb
dentaku-3.4.1 lib/dentaku/ast/functions/avg.rb
dentaku-3.4.0 lib/dentaku/ast/functions/avg.rb