Не уверен насчет шага.
Первый подход определяет, сколько уникальных шагов в диапазонах.
Второй подход проверяет количество необходимых шагов для каждого диапазона в строке диапазонов и учитывает только уникальное количество шагов.
var rane1 = " -09.00_-6.50_0.50,-6.00_0.00_0.25,+0.25_+4.00_0.50";
var rane2 = " -04.00_-9.25_0.25,-09.00_-6.50_0.50,-6.00_0.00_0.25,+0.25_+8.00_0.50";
const dynamicRange = (ranges) => {
//set to count different step
const counter = new Set();
//reduce to count min max value for each range
const minMax = ranges.split(/\,\s*/).reduce((res, range) => {
const [start, end, step] = range.split('_');
counter.add(step)
return [
res[0]&&parseFloat(res[0])<parseFloat(start) ? res[0] : start,
res[1]&&parseFloat(res[1])>parseFloat(end) ? res[1] : end,
]
}, [])
//return [start, end, different step]
return [...minMax, counter.size]
}
//count different steps need for each range
const dynamicRangeDiffSteps = (ranges) => {
//set to count unique number of steps needs for each range
const counter = new Set();
//reduce to count min max value for each range
const minMax = ranges.split(/\,\s*/).reduce((res, range) => {
const [start, end, step] = range.split('_');
//convert start, end step to float
const sFloat = parseFloat(start), eFloat = parseFloat(end), stepFloat = parseFloat(step)
//add number of steps needed to set
counter.add((eFloat-sFloat)/stepFloat)
return [
res[0]&&parseFloat(res[0])<sFloat ? res[0] : start,
res[1]&&parseFloat(res[1])>eFloat ? res[1] : end,
]
}, [])
//return [start, end, different step]
return [...minMax, counter.size]
}
console.log(dynamicRange(rane1))
console.log(dynamicRange(rane2))
console.log(dynamicRangeDiffSteps(rane1))
console.log(dynamicRangeDiffSteps(rane2))
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>