Return the number of times x appears in the list
(
_mc: &'gc Mutation<'gc>,
receiver: Value<'gc>,
args: Vec<Value<'gc>>,
)
| 282 | |
| 283 | // Return the number of times x appears in the list |
| 284 | fn count<'gc>( |
| 285 | _mc: &'gc Mutation<'gc>, |
| 286 | receiver: Value<'gc>, |
| 287 | args: Vec<Value<'gc>>, |
| 288 | ) -> Result<Value<'gc>, VmError> { |
| 289 | let list = receiver.as_array()?; |
| 290 | |
| 291 | if args.is_empty() { |
| 292 | return Err(VmError::RuntimeError("count: expected 1 argument".into())); |
| 293 | } |
| 294 | |
| 295 | let value_to_count = &args[0]; |
| 296 | |
| 297 | let count = list |
| 298 | .borrow() |
| 299 | .data |
| 300 | .iter() |
| 301 | .filter(|item| item.equals(value_to_count)) |
| 302 | .count(); |
| 303 | |
| 304 | Ok(Value::Number(count as f64)) |
| 305 | } |
| 306 | |
| 307 | // Sort the items of the list in place |
| 308 | fn sort<'gc>( |
nothing calls this directly
no test coverage detected