Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const normalize_offsets = offsets => {
let arr = offsets.slice();
if (arr[0] === undefined) arr[0] = 0;
if (arr[arr.length - 1] === undefined) arr[arr.length - 1] = 1;
let i = 0, j, start, start_offset, increment;
while (i < arr.length) {
if (arr[i] === undefined) {
start = i;
start_offset = arr[i - 1];
j = i;
while (arr[++j] === undefined);
increment = (arr[j] - start_offset) / (j - i + 1);
while (i < j) {
arr[i] = start_offset + (i - start + 1) * increment;
i++;
}
}
i++;
};
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.