I'm trying a JavaScript challenge and I can't figure out how to approach it. Trying to replicate the _.flip Lodash method. I've been able to negate all arguments a function passes doing this:
function invert(func) {
return function () {
return !func(...arguments);
}
};
But can't figure out how to reverse them instead of negate them. I've seen some threads talking about reverse methods, but don't contemplate the idea of several arguments.
Anyone knows how to approach this problem? Thanks in advance.
function flip(func) {
return function() {
func(...Array.from(arguments).reverse());
}
}