numbas / Numbas

A completely browser-based e-assessment/e-learning system, with an emphasis on mathematics
http://www.numbas.org.uk
Apache License 2.0
205 stars 119 forks source link

Defined Max and Min functions for Ranges #1038

Closed Kalanithi96 closed 1 year ago

Kalanithi96 commented 1 year ago

This solves issue #1028

The current implementation of Min and Max function for a Range:

  1. Range is converted to List
  2. Then it is sorted
  3. Finally Min and Max are calculated as first and last elements respectively

This branch utilizes the following structure of a Range to return min and max:

var TRange = types.TRange = function(range) {
    this.value = range;
    if(this.value!==undefined)
    {
        this.start = this.value[0];
        this.end = this.value[1];
        this.step = this.value[2];
        this.size = Math.floor((this.end-this.start)/this.step);
    }
}

The Minimum of a TRange range is range[0] and The Maximum of a TRange range is range[1]

Kalanithi96 commented 1 year ago

Hi @christianp This is my first contribution. Could you advice me on how to proceed here?

christianp commented 1 year ago

This looks great, thanks! You've done everything you need to do. I've merged it in and added some unit tests.