How to resolve the algorithm Averages/Arithmetic mean step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Averages/Arithmetic mean step by step in the Wren programming language
Table of Contents
Problem Statement
Write a program to find the mean (arithmetic average) of a numeric vector. In case of a zero-length input, since the mean of an empty set of numbers is ill-defined, the program may choose to behave in any way it deems appropriate, though if the programming language has an established convention for conveying math errors or undefined values, it's preferable to follow it.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Averages/Arithmetic mean step by step in the Wren programming language
Source code in the wren programming language
class Arithmetic {
static mean(arr) {
if (arr.count == 0) Fiber.abort("Length must be greater than zero")
return arr.reduce(Fn.new{ |x,y| x+y }) / arr.count
}
}
Arithmetic.mean([1,2,3,4,5]) // 3
You may also check:How to resolve the algorithm Factorial step by step in the C# programming language
You may also check:How to resolve the algorithm Isqrt (integer square root) of X step by step in the Tiny BASIC programming language
You may also check:How to resolve the algorithm Sylvester's sequence step by step in the RPL programming language
You may also check:How to resolve the algorithm Maze generation step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Last letter-first letter step by step in the Ruby programming language