Created
May 13, 2019 16:54
-
-
Save danburzo/97fdeca94620f1d234c4a870a72b95fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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