Skip to content

min() and max() do not support strings #829

Closed

Description

@JennaSys

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.

Activity

  1. JennaSys commented on Apr 27, 2023

    @JennaSys
    CollaboratorAuthor

    Also consider issue #305 for supporting a key function.

  2. JennaSys commented on Jul 5, 2024

    @JennaSys
    CollaboratorAuthor

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

  3. self-assigned this
    on Jul 5, 2024
  4. JennaSys commented on Jul 17, 2024

    @JennaSys
    CollaboratorAuthor

    Merged to master on PR #876

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions