const data = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9]
const dataNice = [0, 2, 4, 6, 8]
const data = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2]
const dataNice = [0, 0,5, 1, 1.5, 2]
const data = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9];
const data2 = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2];
function narrow(data, length, precision) {
const start = data[0];
const end = data[data.length-1];
const result = new Array(length);
let step = (end - start) / (length - 1);
if(precision) {
if(step < precision)
throw new RangeError(`Шаг не может быть кратен ${precision} при длине результирующего массива ${length}`);
step = (step / precision | 0) * precision;
}
result[0] = start;
while(--length)
result[length] = step * length;
return result;
}
console.log(
narrow(data, 5, 0.5)
)
console.log(
narrow(data2, 5)
)
console.log(
narrow(data, 5)
)