Skip to content

Overriding function using math.import does not override that function when using evaluate function #2651

Answered by josdejong
Liam-OShea asked this question in Q&A
Discussion options

You must be logged in to vote

The max function accepts both an array like max([1, 2, 3]) or variable arguments like max(1, 2, 3). In your example you use both notations. Your custom version works for max([a, b, c]), where you pass one argument which is an array, but what your custom version is missing is handling the case where a user enters max(a, b, c): you only look at the first argument. To fix this, your implementation should do something like:

const defaultMaxFunc = mathjs.max;
const newMaxFunc = factory('max', [], () => {
  return (...args) => {
    // args is always an array, and can hold either a list with singular values, or a single array or Matrix

    // ... adjust null values here...

    return defaultM…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by josdejong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2350 on August 17, 2022 08:33.