Transcrypt icon indicating copy to clipboard operation
Transcrypt copied to clipboard

min() and max() do not support strings

Open JennaSys opened this issue 3 years ago • 1 comments

I didn't see an exception listed in the docs, but the min() and max() translations are currently using the JS Math.min() and Math.max() which only support numbers, whereas the Python version also supports string types in the iterable.

// Maximum of n numbers
export function max (nrOrSeq) {
    return arguments.length == 1 ? Math.max (...nrOrSeq) : Math.max (...arguments);       
};

// Minimum of n numbers
export function min (nrOrSeq) {
    return arguments.length == 1 ? Math.min (...nrOrSeq) : Math.min (...arguments);       
};

If used with an iterable containing strings, the translated max/min returns NaN. There are of course workarounds, but this should work the same as CPython or be a documented exception.

JennaSys avatar Sep 28 '22 18:09 JennaSys

Also consider issue #305 for supporting a key function.

JennaSys avatar Apr 27 '23 06:04 JennaSys

Added in dev_3.9.3 branch to be released in v3.9.3

JennaSys avatar Jul 05 '24 07:07 JennaSys

Merged to master on PR #876

JennaSys avatar Jul 17 '24 09:07 JennaSys