( expr: MathJsonExpression, fn: (x: MathJsonExpression) => T )
| 391 | * Apply a function to the arguments of a function and return an array of T |
| 392 | */ |
| 393 | export function mapArgs<T>( |
| 394 | expr: MathJsonExpression, |
| 395 | fn: (x: MathJsonExpression) => T |
| 396 | ): T[] { |
| 397 | let args: MathJsonExpression[] | null = null; |
| 398 | if (Array.isArray(expr)) args = expr; |
| 399 | if (isFunctionObject(expr)) args = expr.fn; |
| 400 | if (args === null) return []; |
| 401 | let i = 1; |
| 402 | const result: T[] = []; |
| 403 | while (i < args.length) { |
| 404 | result.push(fn(args[i])); |
| 405 | i += 1; |
| 406 | } |
| 407 | |
| 408 | return result; |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * Assuming that op is an associative operator, fold lhs or rhs |
no test coverage detected