Higher order functions js [closed]

I have a JavaScript function example that takes a callback function as an argument. I want to modify this example function so that when the callback function is called with certain arguments, it produces a specific output using another function ex.

Here is an illustration of how the example function should work with the provided callback:

example((a, b, c, d) => {
  c(a);
  d(b);
});

example((a, b, c, d, e, f, g) => {
  ex({ a, b, c, d, e, f, g });
});

function ex({ b, d, e, f, g, a, c }) {
  b(a)(c)(d)(e);
  b(f)(g);
}

For the first example call:

c a
d b

For the second example call:

b a c d e
b f g

I need to modify the example function such that it produces the specified output format when the callback function is called with the provided arguments.