Pumlhorse provides a handful of basic math functions. For example, the
add function adds an array of numbers.
- val = 99 - sum = add: - 43 - 11 - $val - log: The sum is $sum # logs "The sum is 153"
You can also write this using the
- val = 99 - sum = +: - 43 - 11 - $val - log: The sum is $sum # logs "The sum is 153"
The same patterns apply for
/). Note that the order of array items matters for
divide. For instance:
- val1 = subtract: - 19 - 5 - 7 - val2 = subtract: - 5 - 7 - 19
In this example,
$val1 would be 7 (19 - 5 -7), whereas
$val2 would be -21 (5 - 7 - 19).
Returns the square of a single number
- val = square: 5 # $val = 25
The stats module contains some basic statistics functions. You must explicitly include it in your scripts
name: Find the average modules: - stats # Must include stats module steps: - avg = average: - 4 - 19 - 21 - 5 - 88 - areEqual: expected: 27.4 actual: $avg
max all take an array of numbers.
max will return the minimum and maximum value in the array, respectively.
In addition to accepting an array of numbers, you can pass an array of objects and a
field expression. The
field describes what value on the object to use in the calculation.
name: Find the median square miles steps: # Populate an array of states - states = value: - name: California geography: squareMiles: 163696 highestPointInFeet: 14505 - name: Alaska geography: squareMiles: 663268 highestPointInFeet: 20310 - name: South Carolina geography: squareMiles: 32020 highestPointInFeet: 3560 - name: Iowa geography: squareMiles: 56272.81 highestPointInFeet: 1671 - mid = median: values: $states field: geography.squareMiles - areEqual: expected: 4 actual: $mid