MCPcopy
hub / github.com/josdejong/mathjs / filterTransform

Function filterTransform

src/expression/transform/filter.transform.js:18–49  ·  view source on GitHub ↗

* Attach a transform function to math.filter * Adds a property transform containing the transform function. * * This transform adds support for equations as test function for math.filter, * so you can do something like 'filter([3, -2, 5], x > 0)'.

(args, math, scope)

Source from the content-addressed store, hash-verified

16 * so you can do something like 'filter([3, -2, 5], x > 0)'.
17 */
18 function filterTransform (args, math, scope) {
19 const filter = createFilter({ typed })
20 const transformCallback = createTransformCallback({ typed })
21
22 if (args.length === 0) {
23 return filter()
24 }
25 let x = args[0]
26
27 if (args.length === 1) {
28 return filter(x)
29 }
30
31 const N = args.length - 1
32 let callback = args[N]
33
34 if (x) {
35 x = _compileAndEvaluate(x, scope)
36 }
37
38 if (callback) {
39 if (isSymbolNode(callback) || isFunctionAssignmentNode(callback)) {
40 // a function pointer, like filter([3, -2, 5], myTestFunction)
41 callback = _compileAndEvaluate(callback, scope)
42 } else {
43 // an expression like filter([3, -2, 5], x > 0)
44 callback = compileInlineExpression(callback, math, scope)
45 }
46 }
47
48 return filter(x, transformCallback(callback, N))
49 }
50 filterTransform.rawArgs = true
51
52 function _compileAndEvaluate (arg, scope) {

Callers

nothing calls this directly

Calls 5

isSymbolNodeFunction · 0.90
isFunctionAssignmentNodeFunction · 0.90
compileInlineExpressionFunction · 0.90
filterFunction · 0.85
_compileAndEvaluateFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…