Ensure math::sum() returns a number when being called on a non-array value

Closes #65
This commit is contained in:
Tobie Morgan Hitchcock 2022-08-27 01:02:29 +01:00
parent e4a7ef4afe
commit 48e0380dbe

View file

@ -150,7 +150,7 @@ pub fn stddev(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn sum(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> { pub fn sum(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) { match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().into_iter().sum::<Number>().into()), Value::Array(v) => Ok(v.as_numbers().into_iter().sum::<Number>().into()),
_ => Ok(Value::None), v => Ok(v.as_number().into()),
} }
} }