It it helps, you can use d3.piecewise, e.g.,
d3.piecewise(["#fc8d62", "#ffd92f", "#66c2a5", "#8da0cb"])
or if you want to specify the interpolator:
d3.piecewise(d3.interpolateLab, ["#fc8d62", "#ffd92f", "#66c2a5", "#8da0cb"])
https://github.com/d3/d3-interpolate/blob/main/README.md#piecewise