Anonymous View
Skip to content

Create a scale method #5

Description

@lpatiny

could be inplace or as a new array

I think we should not throw an error

function scale(array, min, max) {

    var minMax=ML.Stat.array.minMax(array);
if (minMax.max===minMax.min) throw new Error('normalize: max must be different from in');
    var slope=(max-min)/(minMax.max-minMax.min);
    console.log(slope);
    for (var i=0; i<array.length; i++) {
        array[i]=(array[i]-minMax.min)*slope+min;
    }
    console.log(array);
    return array;
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions