Major and minor positions of an array

1

I have arrays that are filled with two variables and I am doing very well but now I have not been able to identify which is the minor value and greater value of a selected point with a slider, I am looking at the Underscore.js library and there are three possible options to choose but I do not know which one will be, can you please help me with my problem?
_.findIndex (array, predicate, [context])
_.findLastIndex (array, predicate, [context])
_.range ([start], stop, [step])
in being options is where I stayed

Chart.types.Line.extend({
name: "LineAlt",
highlightPoints: function(datasetIndex, pointIndexArray){
    var activePoints = [];
    // var activePoints_2 = [];
    var points = this.datasets[datasetIndex].points;
    for(i in pointIndexArray){
        if(points[pointIndexArray[i]]){
        activePoints.push(points[pointIndexArray[i]]);
      }
      //mostrar siguiente punto seleccionado
      // if(points[pointIndexArray[i]+1]){
      //          activePoints_2.push(points[pointIndexArray[i]+1]);
      // }
    }
    //mostrar puntos activos en input
    $("#if_a").val(activePoints[0].value)
    $("#if_b").val(activePoints[0].label)

    change_values()
    this.showTooltip(activePoints);
}
});

 function initChart_custom(data) {
 var data_new = data.split(/\n/)
 var c_1 = []
 var c_2 = []
 data_new.forEach(function(data_f){
data_c = data_f.split(",");
c_1.push(data_c[1]);
c_2.push(data_c[0]);
})
c_1 = c_1.slice(1,c_1.length-1)
c_2 = c_2.slice(1,c_2.length-1)
var lineChartData = {
  "datasets": [{
      "data": c_1,
          "pointStrokeColor": "#1A81C5",
          "fillColor": "rgba(254, 254, 254, 0.4)",
          "pointColor": "#1A81C5",
          "strokeColor": "#5D9CC6"
  }],
      "labels": c_2,
};

var options = {showTooltips: true};
var myLine = new Chart(document.getElementById("canvas").getContext("2d")).LineAlt(lineChartData,    options);
var highlight = function(index){
myLine.highlightPoints(0, [index]);
}
$("#slider").slider({
max: lineChartData.datasets[0].data.length-1,
slide: function( event, ui ) { highlight(ui.value); },

});
}
    
asked by JBS 01.11.2016 в 16:19
source

1 answer

0

Greetings, I already managed to do what I needed, what I wanted to do was traverse an array I have identified a position within a range for example given value is 1.52 and the result should be as it appears in the image. I leave code in case someone needs it later.

var a = c_2 //variable del arreglo o array
var elem_want= parseFloat(document.getElementById('if_b').value);//opteniendo campo del valor requerido
var element_find = {}
a.find(function(element,index){
  element = parseFloat(element)
  if (index<a.length-1){
    if (element<=elem_want && a[index+1]>=elem_want){
      element_find = {
        e_i: element,
        index_i: index,
        e_f: a[index+1],
        index_f: index+1
      }
      return true;
    }
  }
})
alert("elemento 1 c_1: "+ c_1[element_find.index_i]+"elemento 1 c_2: "+ c_2[element_find.index_i] + "\n" + "elemento 2 c_1: "+ c_1[element_find.index_f]+"elemento 2 c_2: "+ c_2[element_find.index_f])
    
answered by 03.11.2016 / 18:38
source