JavaScript's Array.sort
function takes an optional argument
that is used by sort as a comparator function. This is difficult to replicate
in the JS-Interpreter, since execution would need to step through this
function an arbitrary number of times. As a result, the provided
Array.sort
function does not support custom comparator
functions.
If this functionality is needed, the easiest way to implement it is to
monkey patch the environment at runtime. Just add the
Array.prototype.sort
definition shown below, and custom
comparator functions will be fully supported.
Click Parse, then either click Step repeatedly, or click Run once. Open your browser's console for errors.
Back to the JS-Interpreter documentation.