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

Function customFunction

test/unit-tests/expression/node/RelationalNode.test.js:202–217  ·  view source on GitHub ↗
(node, options)

Source from the content-addressed store, hash-verified

200 it('should stringify a RelationalNode with custom toString', function () {
201 // Also checks if the custom functions get passed on to the children
202 const customFunction = function (node, options) {
203 if (node.type === 'RelationalNode') {
204 let ret = node.params[0].toString(options)
205 for (let i = 0; i < node.conditionals.length; i++) {
206 ret += ' ' + node.conditionals[i] + ' ' + node.params[i + 1].toString(options)
207 }
208 return ret
209 } else if (node.type === 'ConstantNode') {
210 switch (node.value) {
211 case 1: return 'one'
212 case 2: return 'two'
213 case 3: return 'three'
214 default: return 'NaN'
215 }
216 }
217 }
218
219 const n = new RelationalNode(['smaller', 'larger', 'smallerEq', 'largerEq', 'equal', 'unequal'], [one, three, two, three, two, two, one])
220

Callers

nothing calls this directly

Calls 2

toStringMethod · 0.65
toHTMLMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…