There’s a native function that seems to do exactly what you want.

image