Hi I am trying to find a index for a number in percentage and integer array. Say arraynum = ['10%','250','20%','500'] and user sends a value 15%,in which range does this number resides? I could find index for a integer number using this code
function test(number, ranges) { for (var i = 0; i < ranges.length; ++i) { if (number < ranges[i]) { return i; } } } var ranges = [2000, 4000, 6000, 999999]; console.log(test(1710, ranges)); Now I have mixture of integer and percentage value inside a array and number that a user pass to this function can be a integer,decimal or percentage How to find in which index does the given number resides? Should I convert all value in the mixture array to some format? How to do this? Can someone please help me with this? Thanks in advance.
number < ranges[i]? I thought you want to compare if it is that number that the user inputted.