Is there a way to find the inverse of a higher order function?

Let’s say I have a higher order function that repeats a function twice:

const twice = f => x => f(f(x))

Is there any way I can write a function where I input the result of an instance of evaluation of twice, and it can return f?

const find_f (twice, result) => f

I have experimented with a lot of versions but can’t seem to find a way to “extract” f from the twice function.