{distance_computation}

this.{method_name} = function(features) {{
    var classIdx = 0, i;
    if (this.nNeighbors == 1) {{
        var minDist = Number.POSITIVE_INFINITY,
            curDist;
        for (i = 0; i < this.nTemplates; i++) {{
            curDist = compute(this.X[i], features, this.power);
            if (curDist <= minDist) {{
                minDist = curDist;
                classIdx = this.y[i];
            }}
        }}
    }} else {{
        var classes = new Array(this.nClasses).fill(0);
        var dists = [];
        for (i = 0; i < this.nTemplates; i++) {{
            dists.push(new Neighbor(this.y[i], compute(this.X[i], features, this.power)));
        }}
        dists.sort(function compare(n1, n2) {{
            return (n1.dist < n2.dist) ? -1 : 1;
        }});
        for (i = 0; i < this.nNeighbors; i++) {{
            classes[dists[i].clazz]++;
        }}
        for (i = 0; i < this.nClasses; i++) {{
            classIdx = classes[i] > classes[classIdx] ? i : classIdx;
        }}
    }}
    return classIdx;
}};